简体   繁体   中英

React Native import or include JS file

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"

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";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM