Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
mismatch value for same variable in conditional rendering?

I'm using conditional rendering to decide if an element is visible or not (hello in this case). However, I found that the condition (added) is true when is printed in the console, but hello doesn't show up. Here is my code in the render() of the component.

  render() {
    let {added}=this.state;
    console.log(added);
    return <div style={{ margin: "5px" }}>
      {added==true && <h1>hello</h1>}
    </div>;
  }

Thank you so much

A little bit of background: added is updated by the component's child. I think it's updated successfully since console prints the expected value.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

change logic like this, use of && will make sure its true and then go for other <h1> tag to render, else if false then not render it

  render() {
    let {added}=this.state;
    console.log(added);
    return <div style={{ margin: "5px" }}>
      {added && <h1>hello</h1>}
    </div>;
  }

if you want to use ternary conditions operator ? :, do like this syntax,

{added == true ? <h1>hello</h1> : null}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!