mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-23 20:23:08 +00:00
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).
33 lines
627 B
JavaScript
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 ...
|
|
}
|
|
}
|
|
}
|