React Native:如何将一个文件分割成多个文件并导入? [英] React Native: How to split a file up into multiple files and import them?
本文介绍了React Native:如何将一个文件分割成多个文件并导入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用React Native编写我的第一个应用程序,而我的js文件越来越大.分割文件的正确方法是什么?
I am writing my first app in react native and my js file is getting pretty big. What is the proper way to split the file up.
如果我有类似的东西
var MyClass = React.createClass({
...
})
我可以将其保存在myclass.js
并通过某些命令包含在另一个js文件中吗?
Can I save it at myclass.js
and include in by some command in another js file?
推荐答案
通常,您可以执行以下操作:
In general you can do the following:
var MyClass = React.createClass({
...
)}
module.exports = MyClass;
通过这种方式,您可以知道哪些内容可以公开获得.
This way you tell what should be publicly available.
然后,在您以前的大文件中,您可以像这样加载内容:
And then, in your former big file you can load the contents like this:
var MyClass = require('./myclass.js');
Require返回引用module.exports值的对象.
Require returns the object that references the value of module.exports.
这篇关于React Native:如何将一个文件分割成多个文件并导入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文