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

180
Views
How to execute a function after setting a state in React Native?

my problem is I need to execute a function (getCupons) after setting the two states setPagenumber and setMoreresults but this two functions are asynchronous and don't have a callback. Thanks

const [pageNumber, setPagenumber] = useState(1);
const [moreResults, setMoreresults] = useState(true);
const isFocused = useIsFocused();


useEffect(() => {
    setPagenumber(1);
    setMoreresults(true);
    getCupons();
}, [isFocused])
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can create another useEffect, then it will be called when the conditions are met.

  const [pageNumber, setPagenumber] = useState(0);
  const [moreResults, setMoreresults] = useState(false);
  const isFocused = useIsFocused();

  useEffect(() => {
    setPagenumber(1);
    setMoreresults(true);
  }, [isFocused]);

  useEffect(() => {
    if (moreResults && pageNumber === 1) {
      getCupons();
    }
  }, [pageNumber, moreResults]);


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!