Browse Source
Merge pull request #720 from bvaughn/update-on-async-update-again
Update on async update again
main
Brian Vaughn
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
8 additions and
8 deletions
-
examples/update-on-async-rendering/updating-external-data-when-props-change-after.js
-
examples/update-on-async-rendering/updating-external-data-when-props-change-before.js
|
|
@ -20,13 +20,13 @@ class ExampleComponent extends React.Component { |
|
|
|
} |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
this._loadAsyncData(); |
|
|
|
this._loadAsyncData(this.props.id); |
|
|
|
} |
|
|
|
|
|
|
|
// highlight-range{1-5}
|
|
|
|
componentDidUpdate(prevProps, prevState) { |
|
|
|
if (prevState.externalData === null) { |
|
|
|
this._loadAsyncData(); |
|
|
|
this._loadAsyncData(this.props.id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -44,8 +44,8 @@ class ExampleComponent extends React.Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_loadAsyncData() { |
|
|
|
this._asyncRequest = asyncLoadData(this.props.id).then( |
|
|
|
_loadAsyncData(id) { |
|
|
|
this._asyncRequest = asyncLoadData(id).then( |
|
|
|
externalData => { |
|
|
|
this._asyncRequest = null; |
|
|
|
this.setState({externalData}); |
|
|
|
|
|
@ -5,14 +5,14 @@ class ExampleComponent extends React.Component { |
|
|
|
}; |
|
|
|
|
|
|
|
componentDidMount() { |
|
|
|
this._loadAsyncData(); |
|
|
|
this._loadAsyncData(this.props.id); |
|
|
|
} |
|
|
|
|
|
|
|
// highlight-range{1-6}
|
|
|
|
componentWillReceiveProps(nextProps) { |
|
|
|
if (nextProps.id !== this.props.id) { |
|
|
|
this.setState({externalData: null}); |
|
|
|
this._loadAsyncData(); |
|
|
|
this._loadAsyncData(nextProps.id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -30,8 +30,8 @@ class ExampleComponent extends React.Component { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
_loadAsyncData() { |
|
|
|
this._asyncRequest = asyncLoadData(this.props.id).then( |
|
|
|
_loadAsyncData(id) { |
|
|
|
this._asyncRequest = asyncLoadData(id).then( |
|
|
|
externalData => { |
|
|
|
this._asyncRequest = null; |
|
|
|
this.setState({externalData}); |
|
|
|