Vikram Jakkampudi Vikram Jakkampudi - 1 year ago 93
iOS Question

How can i export and import from one file to another in Ract Native

var SummarizeAll=React.createClass({

var self=this;
var org =;
var root=this.props.root;
var name=rootSchema;
var current=root;

return (<ScrollView><View style={{marginLeft:5,marginRight:5}}>

return (<GenreicApp/>)


this is in index.ios.js

var GenericSummary=React.createClass({

return (<View>
<SummarizeAll />

this is in index2.ios.js

how can i export SummarizeAll component into GenericSumnmary Component in index2.ios.js file from index.ios.js file

Answer Source

You need to use Javascript (or rather Node.js) modules:

  1. Place your SummarizeAll class in separate js file (summarize_all.js)
  2. At the end of the js file add module.exports=SummarizeAll;
  3. In the file that you want to use it use require directive: var SummarizeAll = require('./summarize_all');
  4. Then you can similarly require the SummarizeAll component in index.ios.js or elsewhere. Having it in separate file/subdirectory makes it standalone and reusable.

For clarity and better modularisation you can also place the .js file in some subdirectory, in such case require should contain the relative path to your file including subdirectory.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download