Skip to content

Commit

Permalink
use componentDidMount and ignore async results if componenent has bee…
Browse files Browse the repository at this point in the history
…n unmounted
  • Loading branch information
nreese committed Jan 8, 2018
1 parent 479c731 commit ac8df5d
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,28 @@ export class Tutorial extends React.Component {
}
}

async componentWillMount() {
componentWillMount() {
this._isMounted = true;
}

componentWillUnmount() {
this._isMounted = false;
}

async componentDidMount() {
const tutorial = await this.props.getTutorial(this.props.tutorialId);

if (!this._isMounted) {
return;
}

if (tutorial) {
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({
tutorial: tutorial
}, this.setParamDefaults);
} else {
// eslint-disable-next-line react/no-did-mount-set-state
this.setState({
notFound: true,
});
Expand Down

0 comments on commit ac8df5d

Please sign in to comment.