react-navigation createBottomTabNavigator switch TAB refresh interface

Create the bottom navigation bar in the createBottomTabNavigator method. Only when you enter the tab interface for the first time, the data will be loaded. If you click again to enter, you cannot reload or refresh the data; by registering the focus event after the first rendering, you can request to refresh the data again after the focus is obtained. Yes; the event can be removed when the component is uninstalled

  componentDidMount() {
    
    
    this.fetchData()
    this._navListener = this.props.navigation.addListener('didFocus', () => {
    
     this.fetchData(); })
  }

  componentWillUnmount(){
    
    
    this._navListener.remove();
  }

  fetchData = () => {
    
    
    ...
  }

Guess you like

Origin blog.csdn.net/nongminkouhao/article/details/107819650