From 8403a28adc1fbfccd1dc351d4e0f359ede3fe7e5 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 (cherry picked from commit 09f0a06b8ac86195f16aa476dbd85233d7b42a9a) --- docs/docs/05-reusable-components.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/docs/05-reusable-components.md b/docs/docs/05-reusable-components.md index 89d16b8317..f3182582aa 100644 --- a/docs/docs/05-reusable-components.md +++ b/docs/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: >