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

180
Vistas
Why does the view not update when I update my JSX after initialization?

I am a beginner in JSX and I need to use lifecycles to prevent some bug when loading an editor from primereact.

However, to make this example more simple, I want to update some string value after initialization and see it in my view.

This is my attempt:

let displayText = '<div>Hello World!</div>';

useEffect(() => {
    displayText = '<div>Bye World!</div>;
}, []);

return (<div>{displayText}</div>)

When I run this, I only see "Hello World!". But I expected to see "Bye World", since the variable got updated. What happened here? And how can I achieve this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want an update to cause a render, you can't just assign a variable. A render is triggered after a prop change or a state change. Try converting your variable to a state:

const [displayText, setDisplayText] = useState('<div>Hello World!</div>');

useEffect(() => {
    setDisplayText('<div>Bye World!</div>);
}, []);

return (<div>{displayText}</div>)

That way, after the first render, the effect will trigger, the state will change, and it will render again with the new value.

useState documentation: https://reactjs.org/docs/hooks-reference.html#usestate

Also, you will render the string <div>Hello World!</div>, not a HTML div element.

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