What is New in React-Navigation 5.x
React Navigation

What is New in React-Navigation 5.x

React Navigation heavily used in the React Native Applications. React Navigation 5.15 version released yesterday (release notes), let's see important changes in release 5.x.

Note: By default, React Navigation applies optimizations to screen components to prevent unnecessary renders. Using a render callback removes those optimizations. So if you use a render callback, you'll need to ensure that you use React.memo or React.PureComponent  for your screen components to avoid performance issues.

Screen

Screen components are used to configure various aspects of screens inside a navigator.

React-Navigation

Props

name

It is also used for the name property in the route.

No alt text provided for this image

options

Options to configure how the screen gets presented in the navigator. It accepts either an object or a function returning an object

No alt text provided for this image

When you pass a function, it'll receive the route and navigation

No alt text provided for this image

See Options for screens for more details and examples.

getId

Callback to return an unique ID to use for the screen. It receives an object with the route params. This is easier alternative to specifying a key during `navigate` to control unique instances of a screen. 

e.g. - when params.userId is used as an ID, subsequent navigation to the screen with the same userId will navigate to the existing screen instead of adding a new one to the stack. If the navigation was with a different userId, then it'll add a new screen.

No alt text provided for this image

component

No alt text provided for this image

getComponent

You can use this approach instead of the component prop if you want the ProfileScreen module to be lazily evaluated when needed. This is especially useful when using ram bundles to improve initial load.

No alt text provided for this image

children

You can use this approach instead of the component prop if you need to pass additional props. Though we recommend using React context for passing data instead.

No alt text provided for this image


要查看或添加评论,请登录

Jayesh Shinde的更多文章

社区洞察

其他会员也浏览了