Difference between “lazyLoad” and “lazy” in react-navigation options

喜欢而已 提交于 2019-12-13 03:34:29

问题


I had a problem re-rendering my component on tabs change, and apparently adding lazyLoad: true to the navigation options solved it.

But I don't understand very well how it works...especially before that, I had another problem and adding lazy: true to options solved it.

so my question is, what is the difference between the two and how they work in react-navigation :)


回答1:


There are two major releases of react navigation, react-navigation-v1 and react-navigation-v2

When react-navigation loads up a navigator e.g TabNavigator, it tries to render all the screens inside that navigator.

For react-navigation-v1: When the TabNavigator is mounted on the screen, It tries to push all the screens/components configured inside itself at once to the UI. So to avoid this behavior, in the TabNavigator options, lazyLoad: true or lazy: true is passed, so the Screens/Components can be rendered as required.

Until react-navigation 1.0.0-beta9, lazyLoad: true was used, but since it is stable now, lazy: true is used.

For react-navigation-v2: TabNavigator and createTabNavigator are deprecated, you will always get that yellow screen error, so use createBottomTabNavigator and/or createMaterialTopTabNavigator . The lazy option works with TabNavigator and createTabNavigator, createBottomTabNavigator has lazyLoading option built in, but createMaterialTopTabNavigator seems to buggy, the lazy option does not work.

I hope this answers your question.



来源:https://stackoverflow.com/questions/47890571/difference-between-lazyload-and-lazy-in-react-navigation-options

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