Browse Source

Fixed example props/prevProps

main
Brian Vaughn 7 years ago
parent
commit
9113b4c829
  1. 8
      examples/update-on-async-rendering/updating-external-data-when-props-change-after.js
  2. 8
      examples/update-on-async-rendering/updating-external-data-when-props-change-before.js

8
examples/update-on-async-rendering/updating-external-data-when-props-change-after.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});

8
examples/update-on-async-rendering/updating-external-data-when-props-change-before.js

@ -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});

Loading…
Cancel
Save