Created
April 13, 2016 22:47
-
-
Save haochuan/51f236152b5c7baee59c899ee558ed3e to your computer and use it in GitHub Desktop.
React Component import/export
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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