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

163
Views
Have to make synchronous calls from Button onClick in React

I have button which is making two calls in onClick, a function resetFilterItems which resets the filter in my state and simultaneously my getNetworkViewData is also api is also called.

I am not able to reset my filters firsts so making a call with incorrect payload. How can I first reset the filters props.filterStatus, props.filterCapabilities and then make a call synchronously in this situation?

               <Button
                type="secondary"
                onClick={() => {
                  props.resetFilterItems(
                    props.filterStatus,
                    props.filterCapabilities
                  );
                  props.getNetworkViewData(
                    getSearchQueryParam(),
                    props.partnerId
                  );
                }}
                size="medium"
              >
                Clear all
              </Button>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Try to call your another method in the resetFilterItems in this method.

So that way your state will clear and you can call another method after that.

Or share those 2 methods to get an idea more about your code flow.

You can use useEffect with your state dependencies. And call your Api in useEffect whenever you change your state.

useEffect(()=>{
                 props.getNetworkViewData(
                    getSearchQueryParam(),
                    props.partnerId
                  );
},[props.filterStatus])

Or you want to reset your states after API call then reset them in API response method.

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