假设我有两个屏幕:
- 屏幕 A
- 屏幕 B
我最初登陆的是屏幕A。当我单击 Button
时,我导航到 Screen B。当我按下 后退按钮
时,我再次导航到 屏幕 A。
当我导航到上述场景中提到的屏幕 A 时,我想调用 Action 创建器。
我只想知道每次显示屏幕时将调用哪个生命周期事件。
难道没有像componentWillAppear()
这样的事件吗?
注意:我正在使用 react-native
和 react-navigation
进行导航。
最佳答案
这现在可以通过他们的听众通过简单的 react 导航来完成:
在您的组件 A 中:
componentDidMount = () => {
this._componentFocused();
this._sub = this.props.navigation.addListener(
'didFocus',
this._componentFocused
);
}
componentWillUnmount() {
this._sub.remove();
}
_componentFocused = () => {
this.setState({dataToShow});
}
关于javascript - 当屏幕出现时调用哪个生命周期事件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47627663/