Answer the question
In order to leave comments, you need to log in
How do I update the data on my previous page when I return to it?
I am using React Navigation in my app. How do I update the reducer on my previous page when returning to it?
Practical example: Currently in page A I will navigate to page B where I update the data in my reducer which is rendered in page A . After I navigate () to page A after changing the data in the reducer, I want page A to now overwrite and contain the new data from the reducer. The data is updated when I go from the main page to page A . ShouldComponentUpdate() does not see the update at all, and the value of nextProps, nextState was still not updated?
Answer the question
In order to leave comments, you need to log in
1. in the attachment root:
const doUpdateA = ()=> {
this.setState({updateA: +new Date()})
}
and props doUpdateA and this.state.updateA down the navigation stack
2. to B before jumping back call doUpdateA
3. in A:
static getDerivedStateFromProps(nextProps, currentState) {
if (nextProps.updateA !== currentState.updateA ) {
return {updateA : nextProps.updateA}
componentDidUpdate(prevProps, prevState) {
if (this.state.updateA !== prevState.updateA) {
// do update A stuff
}
Something like this.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question