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

88
Views
Ansynchronous function in useEffect hook dependancy array

Can we pass an asynchronous function (example fetchData() ) in a dependancy array of useEffect of a react component ? example : useEffect(()=>{fetchData().then(data=>{ //do something with data like setting state )}},[fetchData])

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

0

Yes this is fine. Just be aware that a new, potentially overlapping, request will be made every time fetchData changes. If you only want to make this request once use an empty dependency array.

about 4 years ago · Juan Pablo Isaza Report

0

yes for sure but you need to pass empty dependency to avoid overlapping or pass an state array dependency:

useEffect(() => {
    async function fetchMyAPI() {
      let response = await fetch('api/data')
      response = await response.json()
      dataSet(response)
    }
    fetchMyAPI()
}, [])
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!