Reputation: 165
How to create each page in each js files (react-native)? How to include second page in this construction? Or how should I need to include?
var SecondPage = React.createClass({
render: function() {
return (
);
}
});
Upvotes: 1
Views: 313
Reputation: 9143
What you're missing is exporting your react component so it can be used in other js files.
Put your second page code in a separated file, for example: secondPage.js. This file would look somthing like this:
'use strict';
var React = require('react-native');
var SecondPage = React.createClass({
render: function() {
return (
);
},
});
module.exports = SecondPage;
To use your component just import it using require. (and don't forget to set the correct path to the new script file):
var React = require('react-native');
var SecondPage = require('./path_to_script/SecondPage');
var {
AppRegistry,
} = React;
var MyApp = React.createClass({
render: function() {
return (
<SecondPage />
);
},
});
AppRegistry.registerComponent('MyApp', () => MyApp);
Upvotes: 3