From 7793db16b0485b34b63b1ebdb40ff13cc161c62a Mon Sep 17 00:00:00 2001 From: Tanase Hagi Date: Sun, 14 Aug 2016 20:04:47 +0300 Subject: [PATCH] Add propsTypes and defaultProps example for stateless functions (#7458) * Add propsTypes and defaultProps example for stateless functions * Update 05-reusable-components.md * Update 05-reusable-components.md --- docs/05-reusable-components.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/05-reusable-components.md b/docs/05-reusable-components.md index 89d16b83..f3182582 100644 --- a/docs/05-reusable-components.md +++ b/docs/05-reusable-components.md @@ -294,7 +294,19 @@ ReactDOM.render(, mountNode); ``` This simplified component API is intended for components that are pure functions of their props. These components must not retain internal state, do not have backing instances, and do not have the component lifecycle methods. They are pure functional transforms of their input, with zero boilerplate. -However, you may still specify `.propTypes` and `.defaultProps` by setting them as properties on the function, just as you would set them on an ES6 class. + +However, you may still specify `.propTypes` and `.defaultProps` by setting them as properties on the function, just as you would set them on an ES6 class: + +```javascript +const HelloMessage = (props) =>
Hello, {props.name}
; +HelloMessage.propTypes = { + name: React.PropTypes.string +} +HelloMessage.defaultProps = { + name: 'John Doe' +} +ReactDOM.render(, mountNode); +``` > NOTE: >