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.

32 lines
581 B

// After
class ExampleComponent extends React.Component {
// highlight-next-line
_hasUnmounted = false;
state = {
externalData: null,
};
// highlight-range{1-7}
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 ...
}
}
}