Skip to content

Instantly share code, notes, and snippets.

@haochuan
Created April 13, 2016 22:47
Show Gist options
  • Select an option

  • Save haochuan/51f236152b5c7baee59c899ee558ed3e to your computer and use it in GitHub Desktop.

Select an option

Save haochuan/51f236152b5c7baee59c899ee558ed3e to your computer and use it in GitHub Desktop.
React Component import/export
// form.js and home.js are in the same dir
// If ES5, var Home = React.createClass({....})
class Form extends Component {
// If ES5, do not need this
constructor(props, contexts) {
super(props, contexts);
}
componentDidMount() {
// here is when to get data from API if needed
}
render() {
return (
<div>
<form>
<input />
<input />
<input />
</form>
</div>
);
}
}
export default Form // If ES5: module.exports = Form
import Form from './form'; // If ES5: var Form = require('./form');
// form.js and home.js are in the same dir
// If ES5, var Home = React.createClass({....})
class Home extends Component {
// If ES5, do not need this
constructor(props, contexts) {
super(props, contexts);
}
componentDidMount() {
// here is when to get data from API if needed
}
render() {
return (
<div>
<Form />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment