Skip to content

Instantly share code, notes, and snippets.

@benjdlambert
Created September 5, 2016 11:19
Show Gist options
  • Save benjdlambert/c1ffdd7b26e581293cb81c381c6f0b06 to your computer and use it in GitHub Desktop.
Save benjdlambert/c1ffdd7b26e581293cb81c381c6f0b06 to your computer and use it in GitHub Desktop.
Static Properties on Components
// old way
class TestComponent extends React.Component {
render() {
return <h1>{this.props.header}</h1>
}
}
TestComponent.defaultProps = {
header: 'hello',
};
TestComponent.propTypes = {
header: React.PropTypes.string,
};
// new way
class TestComponent extends React.Component {
static defaultProps = {
header: 'hello',
}
static propTypes = {
header: React.PropTypes.string,
}
render() {
return <h1>{this.props.header}</h1>
}
}
@revett
Copy link

revett commented Sep 5, 2016

Looks good!

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