屏幕出现时,将调用哪个生命周期事件? [英] Which lifecycle event is called when a screen appears?
问题描述
假设我有两个屏幕:
- 屏幕A
- 屏幕B
我最初登陆屏幕A .单击Button
时,我导航到屏幕B .当我按下Back Button
时,我再次导航到屏幕A .
I am initially landed on Screen A. When I click on a Button
I navigate to Screen B. When I press Back Button
, I am again navigated to Screen A.
如上所述,当我导航到屏幕A 时,我想打电话给动作创建者.
I want to call an action creator when I am navigated to Screen A as mentioned in above scenario.
我只想知道每次显示屏幕时都会调用哪个生命周期事件.
I just want to know that which lifecycle event will be called every time when a screen is presented.
没有像componentWillAppear()
这样的事件吗?
注意:我正在将react-native
和react-navigation
用于导航.
Note: I am using react-native
with react-navigation
for navigation.
推荐答案
现在可以通过其侦听器进行简单的反应导航:
This can now be done with plain react navigation via their listeners:
在组件A中:
componentDidMount = () => {
this._componentFocused();
this._sub = this.props.navigation.addListener(
'didFocus',
this._componentFocused
);
}
componentWillUnmount() {
this._sub.remove();
}
_componentFocused = () => {
this.setState({dataToShow});
}
这篇关于屏幕出现时,将调用哪个生命周期事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!