Saturday, May 11, 2024
158
rated 0 times [  164] [ 6]  / answers: 1 / hits: 15310  / 9 Years ago, sat, october 3, 2015, 12:00:00

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



var MyClass = React.createClass({
...
})


Can I save it at myclass.js and include in by some command in another js file?


More From » react-native

 Answers
11

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.


[#64848] Thursday, October 1, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
reecep

Total Points: 141
Total Questions: 95
Total Answers: 113

Location: Finland
Member since Mon, Nov 8, 2021
3 Years ago
reecep questions
Wed, Dec 8, 21, 00:00, 2 Years ago
Fri, Jul 30, 21, 00:00, 3 Years ago
Wed, Nov 18, 20, 00:00, 4 Years ago
Sat, Mar 14, 20, 00:00, 4 Years ago
Mon, Feb 3, 20, 00:00, 4 Years ago
;