react-lifecycle

Can't call setState (or forceUpdate) on an unmounted component

半城伤御伤魂 提交于 2019-12-03 06:49:56
问题 I'm trying to fetch the data from the server after component has been updated but I couldn't manage to do that. As far as I understand componentWillUnmount is called when component is about to be destroyed, but I never need to destroy it so it's useless to me. What would be solution for this? When I should set the state? async componentDidUpdate(prevProps, prevState) { if (this.props.subject.length && prevProps.subject !== this.props.subject) { let result = await this.getGrades({ student:

Can't call setState (or forceUpdate) on an unmounted component

时光毁灭记忆、已成空白 提交于 2019-12-02 20:29:09
I'm trying to fetch the data from the server after component has been updated but I couldn't manage to do that. As far as I understand componentWillUnmount is called when component is about to be destroyed, but I never need to destroy it so it's useless to me. What would be solution for this? When I should set the 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.setState({ subject: this.props.subject, grades: result