How to render a component only once in React Native

I am using Expo + React Navigation.

My React Native applications have many screens that use the Map component. I do not want this component to be re-displayed when switching the screen. Is there a way to save my Map component in some kind of storage so that every time I need a Map , my application does not need to re-display it?

+5
source share
2 answers

If you want something not to redraw. You indicated this on the index page. If you specify it on the index page, access to it will be available everywhere in the project.

Example:

Whenever I use firebase, I initialize firebase in the index.js file.

+1
source

Perhaps you could play with shouldComponentUpdate() of the Map component.

Try returning true only for the first rendering, and then return false for function calls to tell React not to reprocess your component.

0
source

Source: https://habr.com/ru/post/1276209/


All Articles