简体   繁体   English

React Native 导入或包含 JS 文件

[英]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:如果我有超过 300 个功能组件文件需要导入一个名为“main.js”的文件中,而不是像这样添加 300 行导入:

import C1 from "./pages/C1";从“./pages/C1”导入 C1;

. .

. .

. .

import C300 from "./pages/C300";从“./pages/C300”导入 C300;

i want to put those 300 imports in an external file called "myImports.js",then include/import this "myImports.js" in "main.js"我想把这 300 个导入放在一个名为“myImports.js”的外部文件中,然后在“main.js”中包含/导入这个“myImports.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或者,您可以做更好的方法是创建一个新文件夹,如components并将所有 300 个文件放入其中并在其中创建新文件,名称如index.js并复制下面的代码,如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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