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.
34 lines
593 B
34 lines
593 B
7 years ago
|
// After
|
||
|
class ExampleComponent extends React.Component {
|
||
|
// highlight-next-line
|
||
|
_hasUnmounted = false;
|
||
|
|
||
|
state = {
|
||
|
externalData: null,
|
||
|
};
|
||
|
|
||
|
// highlight-range{1-9}
|
||
|
componentDidMount() {
|
||
|
asyncLoadData(
|
||
|
this.props.someId
|
||
|
).then(externalData => {
|
||
|
if (!this._hasUnmounted) {
|
||
|
this.setState({externalData});
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
|
||
|
// highlight-range{1-3}
|
||
|
componentWillUnmount() {
|
||
|
this._hasUnmounted = true;
|
||
|
}
|
||
|
|
||
|
render() {
|
||
|
if (this.externalData === null) {
|
||
|
// Render loading state ...
|
||
|
} else {
|
||
|
// Render real UI ...
|
||
|
}
|
||
|
}
|
||
|
}
|