我已经在以下方面采取了行动componentDidMount
:
componentDidMount() {
this.props.getQuests();
}
并且想在完成后触发另一个动作,我使用了生命周期方法componentWillReceiveProps
componentWillReceiveProps = async nextProps => {
if (nextProps.questObject.length !== 0) {
const authToken = await AsyncStorage.getItem("authToken");
this.props.getProfile(authToken);
}
};
然而,只有this.props.getQuests();
被解雇,第二个动作this.props.getProfile(authToken)
没有被解雇。
const mapStateToProps = ({ quest, profile }) => {
const { error, loading, questObject } = quest;
const { profileObj } = profile;
return { error, loading, questObject, profileObj };
};
export default connect(
mapStateToProps,
{ getQuests, getProfile }
)(HomeScreen);
目前它返回以下错误:
Warning: Can't call setState (or forceUpdate) on an unmounted
component. This is a no-op, but it indicates a memory leak in your
application. To fix, cancel all subscriptions and asynchronous tasks in
the componentWillUnmount method.