How to store all imported modules in one file

Viewed 74

I am developing an app with react native and I have a lot of imported modules on different pages. Most of the imported modules are the same on every page for example:

import { Text, View, Image } from 'react-native';

I am using this on many pages. I was wondering if there is a way to store modules like this on one page and call them from what ever page I want.

1 Answers

If you are creating the same type of views in most of your screens then create a separate component and reuse it in all the screens by changing its props as a requirement of view management.

It will help to reduce your code and help you to import fewer modules for most of your code.

For example, if we have to show a loader on an async task then we have to show an activity indicator in a modal view, and then we have to import modal, view, and activity indicator.

If we create a component, let’s name it AppLoader, we only have to create a loader at a time and import it and show the loader by managing a state everywhere in our app code simply.

It will help us to reduce the same code.

Related