![](/img/trans.png)
[英]react-native-router-flux refreshing component with Replace, Reset, and Refresh
[英]onEnter/onExit method in React Native Component (react-native-router-flux)
所以我可以在我的应用程序的根目录中使用onEnter / onExit方法在路由器定义中,它完全正常:
<Scene key="arena" hideNavBar={true} onEnter={() => console.log("Entered")} component={ArenaPage} />
有什么方法可以在组件本身内执行此操作,以便我可以更新本地状态??
export default class ArenaPage extends Component {
onEnter () {
this.setState(...)
}
// Render blah blah blah...
}
如果不可能,那么无论如何都要在远离场景(动作。[键])时触发componentWillUnmount
请检查最新的react-native-router-flux:beta.27
,现在您可以定义onEnter,onExit方法作为您的反应组件方法。
class Home extends Component {
static onEnter() {
console.log('On Focus Enter')
};
static onExit() {
console.log('On Focus Exit')
}
}
在arenaPage组件中简单使用componentWillUnmount。
componentWillUnmount() {
// add your code here.
}
因为远离组件导航时会运行。 我正在使用它来删除错误消息。 这很有效。
您可以使用onEnter
和onExit
方法来获得所需的结果。 反过来可以像这样访问this
。
import { Actions } from 'react-native-router-flux'
class Home extends Component {
static onEnter() {
// homeSceneKey needs to be the same key that you use to configure the Scene
Actions.refs.homeSceneKey.getWrappedInstance().myFunction()
};
myFunction = () => {
// have access to this (props and state) here
this.blah = "what ever you want to do"
}
}
希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.