返回页面时尝试重置数据
我试图在返回页面时重置数据,
这是我的一段代码
componentDidMount(){
this.checkIfAlreadyLoggedIn();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.setState({products:[],alreadyLoadedCount:0});
this.checkIfAlreadyLoggedIn();
}
);
}
componentWillUnmount() {
this.willFocusSubscription();
}
,该页面完全重新加载,但问题是当我返回上一页时,以下错误显示
ERROR TypeError: this.willFocusSubscription is not a function. (In 'this.willFocusSubscription()', 'this.willFocusSubscription' is an instance of Object)
我也将上述代码放在上一页中。但错误显示相同。
I am trying to reset data when return to the page
here is my piece of code
componentDidMount(){
this.checkIfAlreadyLoggedIn();
this.willFocusSubscription = this.props.navigation.addListener(
'willFocus',
() => {
this.setState({products:[],alreadyLoadedCount:0});
this.checkIfAlreadyLoggedIn();
}
);
}
componentWillUnmount() {
this.willFocusSubscription();
}
the page is perfectly reload but the problem is when i back to the previous page the follwing error shows
ERROR TypeError: this.willFocusSubscription is not a function. (In 'this.willFocusSubscription()', 'this.willFocusSubscription' is an instance of Object)
i put the above code in the previous page also. but the error shows same.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将 willfocus 更改为 didfocus 并删除它 componentWillUnMount 。它起作用了
I changed willfocus to didfocus and and remove it componentWillUnMount . it is worked
您可以将 'willFocus' 更改为 'focus' 如下图所示并检查

can you change 'willFocus' to 'focus' as show in the image below and check
