Skip to content

Instantly share code, notes, and snippets.

@ryankshaw
Last active August 29, 2015 14:06
Show Gist options
  • Save ryankshaw/82aef3a8fba10ea4a744 to your computer and use it in GitHub Desktop.
Save ryankshaw/82aef3a8fba10ea4a744 to your computer and use it in GitHub Desktop.
proper code structure when defining a React component
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:
@jergason
Copy link

👍

@coderberry
Copy link

Very nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment