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

101
Views
Make an API call in a React functional component with the click of a button

I want to make an API call to the backend with the click of a button in ReactJs. I have found 3 ways that I can do that by reading stackoverflow, tutorials and articles.

  1. Add a simple function inside or outside the functional component that will make the API call (found many tutorials that use this method)

  2. Add a state variable that when changed, it will trigger the useEffect hook (with dependency to the state variable) that will make the API call

  3. Add a useCallback hook on a function and call that to make the API call

My thoughts are that the 1st is easy, simple but is it correct? And the 3rd might be wrong because you are not using the useCallback as intended (passing it to a child component and prevent re-rendering) Which way is correct (if there is another way please suggest) and why?

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

0

If you need only a simple API call, I would go for option 1. Option 2 seems to me too "big" for a simple API call.

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!