Home > OS >  React Native import or include JS file
React Native import or include JS file

Time:01-29

if i have more than 300 Functional Components file that i need to import in a file called "main.js",and instead of adding 300 lines of imports like so :

import C1 from "./pages/C1";

.

.

.

import C300 from "./pages/C300";

i want to put those 300 imports in an external file called "myImports.js" ,then include/import this "myImports.js" in "main.js"

CodePudding user response:

Alternatively you can do the better approach is to create a new folder like components and put all 300 files in it and create new file there name like index.js and copy the code below there like

import C1 from "./pages/C1";
.
.
import C300 from "./pages/C300";

export {
  C1,C2,...C300
};

Your components folder structure like

> components
    ----- C1.js
    ----- C2.js
    .
    .
    ----- C300.js
    ----- index.js // new file create here

Usage like

import { C300 } from "./components";
  •  Tags:  
  • Related