Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native Component Lifecycle on Navigator Pop

Screen1: - loads content from an api over network. - User presses a button to add new item to the list - Screen 2 opens (Navigator.push)

After completing the action on screen 2 (uploading the new item to the list), when user moves back to the screen 1, the object doesn't get updated. I have tried passing an updateobject() method as a prop to the screen 2 but still it doesn't seem to work.

Would really appreciate if someone can help me know if there is a componentlifecycle method that is triggered when navigator goes back to the screen1

like image 687
hangvirus Avatar asked Jan 28 '26 14:01

hangvirus


1 Answers

Just an idea but might be worth checking out something like redux to manage your state.

It really is excellent and it'll allow you to update state centrally (with a reducer) based on things happening in the background or foreground via actions (API requests probably need async actions so check redux-thunk for how).

You then use react-redux to connect parts of this centralised state to your components.

This will mean that you do not need a component lifecycle method as state changes centrally, props will be passed to components and as we all know with react they re-render accordingly.

like image 101
pip Avatar answered Jan 30 '26 11:01

pip



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!