Files
react.dev/examples/update-on-async-rendering/fetching-external-data-after.js
Brian Vaughn f632f220c6 Wording changes for update-on-async and strict-mode
Incorporates most of Sophie's feedback.

Changes update-on-async references to 16.3 to be future tense (since this blog post will be released before 16.3). Changes strict-mode references to be past-tense (since this will be a docs page instead of a blog post).
2018-02-13 10:49:40 -08:00

33 lines
627 B
JavaScript

// After
class ExampleComponent extends React.Component {
state = {
externalData: null,
};
// highlight-range{1-9}
componentDidMount() {
this._currentRequest = asyncLoadData(
this.props.someID,
externalData => {
this._currentRequest = null;
this.setState({externalData});
}
);
}
// highlight-line
// highlight-range{1-5}
componentWillUnmount() {
if (this._currentRequest) {
this._currentRequest.cancel();
}
}
render() {
if (this.externalData === null) {
// Render loading state ...
} else {
// Render real UI ...
}
}
}