How do I force a component to unmount when I navigate to a new page in react native?

萝らか妹 提交于 2019-12-02 05:48:26

问题


I want to make sure the lifecycle method ComponentWillUnmount fires when I navigate to a new page. I found this post, but that doesn't seem to mention anything about navigating to a new page. I also found this post but I'm using react-navigation. In addition, I'm not using pop/push. I'm simply using this.props.navigation.navigate('SomePage') to get to the next page


回答1:


You can use this.props.navigation.replace('routName'); It will do your job.




回答2:


Checkout React Navigation's ways to handle a component's lifecycle event in their docs here

TL;DR, you can checkout React Navigation's navigation lifecycle event to perform actions when you switch screens. Hope it helps.



来源:https://stackoverflow.com/questions/55018589/how-do-i-force-a-component-to-unmount-when-i-navigate-to-a-new-page-in-react-nat

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!