Created
September 5, 2016 11:19
-
-
Save benjdlambert/c1ffdd7b26e581293cb81c381c6f0b06 to your computer and use it in GitHub Desktop.
Static Properties on Components
This file contains 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
// 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> | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks good!