Skip to content

Commit

Permalink
Update example lifecycle methods (#3218)
Browse files Browse the repository at this point in the history
* update async example

* update real world example

* update demo code in docs

* replace componentWillMount

* remove lock files

* replace nextProps with prevProps

* remove lockfile

* fix prevProps -> this.props
  • Loading branch information
gretzky authored and timdorr committed Nov 21, 2018
1 parent afd762f commit 691b9e4
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions docs/api/applyMiddleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ class SandwichShop extends Component {
this.props.dispatch(makeASandwichWithSecretSauce(this.props.forPerson))
}

componentWillReceiveProps(nextProps) {
if (nextProps.forPerson !== this.props.forPerson) {
this.props.dispatch(makeASandwichWithSecretSauce(nextProps.forPerson))
componentDidUpdate(prevProps) {
if (prevProps.forPerson !== this.props.forPerson) {
this.props.dispatch(makeASandwichWithSecretSauce(this.props.forPerson))
}
}

Expand Down
12 changes: 6 additions & 6 deletions docs/recipes/ReducingBoilerplate.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ class Posts extends Component {
this.loadData(this.props.userId)
}

componentWillReceiveProps(nextProps) {
if (nextProps.userId !== this.props.userId) {
this.loadData(nextProps.userId)
componentDidUpdate(prevProps) {
if (prevProps.userId !== this.props.userId) {
this.loadData(this.props.userId)
}
}

Expand Down Expand Up @@ -306,9 +306,9 @@ class Posts extends Component {
this.props.dispatch(loadPosts(this.props.userId))
}

componentWillReceiveProps(nextProps) {
if (nextProps.userId !== this.props.userId) {
this.props.dispatch(loadPosts(nextProps.userId))
componentDidUpdate(prevProps) {
if (prevProps.userId !== this.props.userId) {
this.props.dispatch(loadPosts(this.props.userId))
}
}

Expand Down
6 changes: 3 additions & 3 deletions examples/async/src/containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ class App extends Component {
dispatch(fetchPostsIfNeeded(selectedSubreddit))
}

componentWillReceiveProps(nextProps) {
if (nextProps.selectedSubreddit !== this.props.selectedSubreddit) {
const { dispatch, selectedSubreddit } = nextProps
componentDidUpdate(prevProps) {
if (prevProps.selectedSubreddit !== this.props.selectedSubreddit) {
const { dispatch, selectedSubreddit } = this.props
dispatch(fetchPostsIfNeeded(selectedSubreddit))
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/real-world/src/components/Explore.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ export default class Explore extends Component {
onChange: PropTypes.func.isRequired
}

componentWillReceiveProps(nextProps) {
if (nextProps.value !== this.props.value) {
this.setInputValue(nextProps.value)
componentDidUpdate(prevProps) {
if (prevProps.value !== this.props.value) {
this.setInputValue(this.props.value)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/real-world/src/containers/RepoPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ class RepoPage extends Component {
loadStargazers: PropTypes.func.isRequired
}

componentWillMount() {
componentDidMount() {
loadData(this.props)
}

componentWillReceiveProps(nextProps) {
if (nextProps.fullName !== this.props.fullName) {
loadData(nextProps)
componentDidUpdate(prevProps) {
if (prevProps.fullName !== this.props.fullName) {
loadData(this.props.fullName)
}
}

Expand Down
8 changes: 4 additions & 4 deletions examples/real-world/src/containers/UserPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class UserPage extends Component {
loadStarred: PropTypes.func.isRequired
}

componentWillMount() {
componentDidMount() {
loadData(this.props)
}

componentWillReceiveProps(nextProps) {
if (nextProps.login !== this.props.login) {
loadData(nextProps)
componentDidUpdate(prevProps) {
if (prevProps.login !== this.props.login) {
loadData(this.props.login)
}
}

Expand Down

0 comments on commit 691b9e4

Please sign in to comment.