Skip to content

Commit

Permalink
add lifecycle example in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Pokora committed Nov 19, 2017
1 parent 8c4ac2e commit ea0f97f
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,21 @@ A higher-order component version of [`React.Component()`](https://facebook.githu
Any state changes made in a lifecycle method, by using `setState`, will be propagated to the wrapped component as props.
Example:
```js
const PostsList = ({ posts }) => (
<ul>{posts.map(p => <li>{p.title}</li>)}</ul>
)

const PostsListWithData = lifecycle({
componentDidMount() {
fetchPosts().then(posts => {
this.setState({ posts });
})
}
})(PostsList);
```
### `toClass()`
```js
Expand Down

0 comments on commit ea0f97f

Please sign in to comment.