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

188
Views
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 answers
Answer question

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 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!