React Native: How to split a file up into multiple files and import them?

后端 未结 2 1649
悲哀的现实
悲哀的现实 2021-02-18 14:56

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.

If i have something like

va         


        
2条回答
  •  南笙
    南笙 (楼主)
    2021-02-18 15:30

    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 returns the object that references the value of module.exports.

提交回复
热议问题