Skip to content

Instantly share code, notes, and snippets.

@raulpineda
Created March 3, 2017 12:52
Show Gist options
  • Save raulpineda/05ea4e4f7d047d3853ab76e683a13ae2 to your computer and use it in GitHub Desktop.
Save raulpineda/05ea4e4f7d047d3853ab76e683a13ae2 to your computer and use it in GitHub Desktop.
Boilerplate for creating new React components.
class MyReactComponent extends React.Component {
constructor(props) {
super(props);
this.state = {}
// Event Handlers
// Event handling functions should start with the word handle.
this.handleInteraction = (e) => {
};
// Helper Functions
// Helper functions perform actions, they should start with a verb.
this.doAction = () => {
};
// Partial Renderers
this.renderPartial = () => {
return (/* Should always return jsx or null */);
};
}
componentDidMount() {
// Perform actions that are needed only when the component is first mounted
}
componentWillReceiveProps(nextProps) {
// Perform actions that are needed every time a component's props are updated
}
render() {
return (/* Should always return jsx or null */);
}
}
// Use for default configuration of the component
// These can be overwritten by the component's parent passing props
MyReactComponent.defaultProps = {
// Translation Strings
// Default Internal Configuration
};
// Use for typechecking your component
// https://facebook.github.io/react/docs/typechecking-with-proptypes.html
MyReactComponent.propTypes = {
// Required
// Function References (These must be always required)
// Optional
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment