屏幕出现时调用哪个生命周期事件?

Vis*_*hal 5 javascript lifecycle react-native react-navigation

假设我有两个屏幕:

  • 屏幕A.
  • 屏幕B.

我最初登陆了Screen A.当我点击一个Button导航到Screen B.当我按下时Back Button,我再次导航到Screen A.

当我导航到Screen A上面的场景中时,我想调用一个动作创建者.

我只是想知道每次呈现屏幕时都会调用哪个生命周期事件.

是不是有一些事件componentWillAppear()

注:我使用react-nativereact-navigation用于导航.

And*_*rew 11

现在可以通过他们的听众进行简单的反应导航来完成:

在您的组件A中:

componentDidMount = () => {
  this._componentFocused();

  this._sub = this.props.navigation.addListener(
    'didFocus',
    this._componentFocused
  );
}

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

_componentFocused = () => {
  this.setState({dataToShow});
}
Run Code Online (Sandbox Code Playgroud)

React Navigation docs - 生命周期