Reputation: 21
I am trying to reset data when return to the page
here is my piece of code
componentDidMount(){
this.checkIfAlreadyLoggedIn();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.setState({products:[],alreadyLoadedCount:0});
this.checkIfAlreadyLoggedIn();
}
);
}
componentWillUnmount() {
this.willFocusSubscription();
}
the page is perfectly reload but the problem is when i back to the previous page the follwing error shows
ERROR TypeError: this.willFocusSubscription is not a function. (In 'this.willFocusSubscription()', 'this.willFocusSubscription' is an instance of Object)
i put the above code in the previous page also. but the error shows same.
Upvotes: 0
Views: 140
Reputation: 21
I changed willfocus to didfocus and and remove it componentWillUnMount . it is worked
componentDidMount() {
....
this.focusListener= this.props.navigation.addListener(
'didFocus',
() => {
this.setState({products:[],alreadyLoadedCount:0});
// loading page code
}
);
}
componentWillUnmount() {
this.focusListener.remove();
}
Upvotes: 1
Reputation: 383
can you change 'willFocus' to 'focus' as show in the image below and check
Upvotes: 0