Can't call setState (or forceUpdate) on an unmounted component
A common pattern I use in this instance is something along the lines of
componentWillUnmount() {
this.isCancelled = true;
}
And then in the code where you're awaiting an async function to resolve, you would add a check before setting state:
async componentDidUpdate(prevProps, prevState) {
if (this.props.subject.length && prevProps.subject !== this.props.subject) {
let result = await this.getGrades({
student: this.props.id,
subject: this.props.subject
});
!this.isCancelled && this.setState({
subject: this.props.subject,
grades: result
});
}
}
That will stop any state setting on unmounted/unmounting components