diff --git a/content/docs/typechecking-with-proptypes.md b/content/docs/typechecking-with-proptypes.md index 50c0a1a3..6dc978a0 100644 --- a/content/docs/typechecking-with-proptypes.md +++ b/content/docs/typechecking-with-proptypes.md @@ -147,7 +147,11 @@ MyComponent.propTypes = { You can define default values for your `props` by assigning to the special `defaultProps` property: -```javascript +``` +const defaultProps = { + name: 'Stranger' +}; + class Greeting extends React.Component { render() { return ( @@ -157,9 +161,7 @@ class Greeting extends React.Component { } // Specifies the default values for props: -Greeting.defaultProps = { - name: 'Stranger' -}; +Greeting.defaultProps = defaultProps; // Renders "Hello, Stranger": ReactDOM.render( @@ -168,4 +170,23 @@ ReactDOM.render( ); ``` +You can also put propTypes and defaultProps as static props inside React class. + +``` +class Greeting extends Component { + + static defaultProps = { + name: 'stranger' + } + + render() { + return ( +