You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
566 B
30 lines
566 B
// Before
|
|
class ExampleComponent extends React.Component {
|
|
state = {
|
|
externalData: null,
|
|
};
|
|
|
|
// highlight-range{1-8}
|
|
componentWillMount() {
|
|
this._asyncRequest = loadMyAsyncData().then(
|
|
externalData => {
|
|
this._asyncRequest = null;
|
|
this.setState({externalData});
|
|
}
|
|
);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
if (this._asyncRequest) {
|
|
this._asyncRequest.cancel();
|
|
}
|
|
}
|
|
|
|
render() {
|
|
if (this.state.externalData === null) {
|
|
// Render loading state ...
|
|
} else {
|
|
// Render real UI ...
|
|
}
|
|
}
|
|
}
|
|
|