I am using react-native with react-native-navigation. I would like to reload data when a component is shown. The component is shown when a user clicks on a tab navigation button
For RNN v3, after trying out for quite a couple times, I finally figured out the correct way:
componentDidMount() {
this.navigationEventListener = Navigation.events().bindComponent(this);
}
componentWillUnmount() {
if (this.navigationEventListener) {
this.navigationEventListener.remove();
}
}
componentDidAppear() { // Lazy loading data for RNN
if (this.state.routes.length === 0) {
this.getData();
}
}
The key is that, the binding of event listener is mandatory, otherwise the componentDidAppear() and componentDidDisappear() won't be triggered.