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

149
Views
make useEffect run before render is completed OR an alternative to use Effect

I have functions that I want to execute when state changes. But I don't want them to wait until render is completed, since it doesn't depend on the rendered DOM.

Is there a way to execute a function when certain dependencies change just like useEffect, but not wait until rendering is completed?

I was thinking to use useMemo or useCallback, but it seems not an ideal solution since it uses memory.

Is there a direct solution for this?

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

If the code that you want to execute may call state setters itself, which results in undesirable flickering, you can switch out useEffect for useLayoutEffect, which runs after the DOM mutations from the render have occurred, but before the browser has repainted the screen. As a result, if any state setters get called, and the component renders again, the user won't see the component rendering twice, because the updates all occur before the screen repainting (except for the very last one).

useLayoutEffect has the exact same function signature as useEffect, so making the changes should be quite trivial.

about 4 years ago · Santiago Gelvez 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!