简体   繁体   English

抽屉导航器屏幕出现奇怪的行为

[英]Drawer navigator screens strange behavior

I'm using react-navigation v5 in my expo managed workflow project and the thing that I noticed is that every second time I visit a screen that is attached to a drawer navigator, lifecycle methods are not being invoked...我在世博会管理的工作流项目中使用 react-navigation v5,我注意到的是,每次我访问附加到抽屉导航器的屏幕时,都不会调用生命周期方法......

Here is the example:这是示例:

- DrawerNavigator
  - Screen1
  - Screen2

The first time I visit "Screen1" useEffect hook is being invoked and all of my data is being fetched.我第一次访问“Screen1”时,调用了useEffect钩子,并且正在获取我的所有数据。 Once I navigate from it ( navigate to a "Screen2" ) and go back to "Screen1", nothing is happening ( data is not being fetched again ) ... Is there something that I'm missing because I want on every visit of the "Screen*" my data to be restarted ( fetched again )?一旦我从它导航(导航到“Screen2”)并返回到“Screen1”,什么也没有发生(数据不再被提取) ......是否有什么我想念的东西,因为我想在每次访问“屏幕*”我的数据要重新启动(再次获取)?

Thanks!谢谢!

You will have to use the 'useFocusEffect' which will run everytime the screen is loaded.您将不得不使用每次加载屏幕时都会运行的“useFocusEffect”。

You can find the reference here https://reactnavigation.org/docs/use-focus-effect/你可以在这里找到参考https://reactnavigation.org/docs/use-focus-effect/

useEffect doesnt work like that so when you come back to screen1 which is already mounted and in the stack the effect wont run. useEffect 不会像那样工作,所以当你回到已经安装并且在堆栈中的 screen1 时,效果不会运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM