mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
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
This commit is contained in:
committed by
Brandon Dail
parent
3d38c5cd3b
commit
7793db16b0
@@ -294,7 +294,19 @@ ReactDOM.render(<HelloMessage name="Sebastian" />, 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) => <div>Hello, {props.name}</div>;
|
||||
HelloMessage.propTypes = {
|
||||
name: React.PropTypes.string
|
||||
}
|
||||
HelloMessage.defaultProps = {
|
||||
name: 'John Doe'
|
||||
}
|
||||
ReactDOM.render(<HelloMessage name="Mădălina"/>, mountNode);
|
||||
```
|
||||
|
||||
> NOTE:
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user