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
Tanase Hagi committed
Aug 14, 2016 at 20:04 UTC
09f0a06b8ac86195f16aa476dbd85233d7b42a9a
1 file changed
+13
-1
docs/docs/05-reusable-components.md
+13
-1
@@ -294,7 +294,19 @@ ReactDOM.render(<HelloMessage name="Sebastian" />, mountNode);
294
```
295
296
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.
297
-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.
297
+
298
+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:
299
+
300
+```javascript
301
+const HelloMessage = (props) => <div>Hello, {props.name}</div>;
302
+HelloMessage.propTypes = {
303
+ name: React.PropTypes.string
304
+}
305
+HelloMessage.defaultProps = {
306
+ name: 'John Doe'
307
+}
308
+ReactDOM.render(<HelloMessage name="Mădălina"/>, mountNode);
309
+```
310
311
> NOTE:
312
>