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

405
Views
How to rerun-useEffect() after dispatching an redux action in react native?

I'm working on react native application with redux, The reducer looks something like this,

    reducer = {
      dataA: {},
      dataB: {},
      laoding: false,
      error: false
    }

I have created a redux action which will update dataA object in reducer. I called the action from one of my react-native components in useEffect().

useEffect(() => {
 dispatch(dataA())
}, [])

I haven't passed any dependency array.

Everything works great, But from the same component where I explicitly dispatching an action to update dataB object which will incur update the dataA from the backend itself.

I'm expecting that, whenever i dispatch an action explicitly to update the dataB, the useEffect
should re-run to get the latest updated object values from dataA object.

But it is not happening, Even I try to pass dataA object as dependency to useEffect, it going an infinite loop of useEffect.

And also, dataB object consists boolean value which i want to display alert box when ever i dispatch an action to update dataB.

  dataB = {
   result: {
     success: true || false,
     Message: "Something"
    }
  }

thanks in advance

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

0

I hope this helps you. you can try this :

 useEffect(() => {
    dispatch(dataA())
}, [dataB])

about 4 years ago · Juan Pablo Isaza Report

0

It goes to infinite loop because you update dataA and give dependency dataA which calls this useEffect again and again. You could give dataB as dependency and this means whenever dataB changes call this 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!