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

183
Views
React/Jest How to wait until useEffect has run?

I have the following code:

const doSomething = useCallback(someFunction);

useEffect(() => {
  // doSomething takes in the data and invokes the callback at the end as newData
  doSomething(data, (newData: string) => {
    setData(newData);
  });
}, [data, doSomething]);

When I want to test this, it only works when I use setTimeout with 1 or more ms. I suppose this is because the function in useEffect has not run yet and thus has not updated the component, correct me if I'm wrong. How can I work around this without setTimeout? Or do I need a completely different approach? Help is appreciated.

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

0

maybe try a wrapper function, for example:

async function handleSomething(){
    const res = await doSomthing()
    setData(res)
}

then call this function inside useEffect.

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!