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.
 
 
 
 

45 lines
959 B

// After
class ExampleComponent extends React.Component {
state = {
externalData: null,
};
// highlight-range{1-9}
componentDidMount() {
this._currentRequest = asyncLoadData(
this.props.id,
externalData => {
this._currentRequest = null;
this.setState({externalData});
}
);
}
// highlight-line
// highlight-range{1-11}
componentDidUpdate(prevProps, prevState) {
if (prevProps.id !== this.props.id) {
this._currentRequest = asyncLoadData(
this.props.id,
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 ...
}
}
}