Last active
August 29, 2015 14:06
-
-
Save ryankshaw/82aef3a8fba10ea4a744 to your computer and use it in GitHub Desktop.
proper code structure when defining a React component
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
MyComponent = React.createClass | |
# give your component a DisplayName that is equal to it's file name. | |
# it is helpful so you dont just see <<anonymous>> when react prints | |
# warnings in the console or <Undefined> in the react inspector. | |
displayName: 'MyComponent' | |
# propTypes should be the second thing, after your DisplayName | |
propTypes: | |
# then put the rest of the react specific properties, in this order | |
# ommiting any that you do not have. | |
mixins: [...] | |
statics: | |
getDefaultProps: | |
getInitialState: | |
shouldComponentUpdate: | |
# then put whichever lifecycle methods you have, in this order: | |
componentWillMount: | |
componentDidMount: | |
componentWillRecieveProps: | |
componentWillUpdate: | |
componentDidUpdate: | |
componentWillUnmount: | |
# after all React specific methods, put your custom stuff eg: | |
someCustomFuctionForThisComponent: | |
# the very last thing should be the render method: | |
render: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍