Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda