I've fired an action in componentDidMount
:
componentDidMount() {
this.props.getQuests();
}
and would like to fire another action once it's completed, I've used the lifecycle method componentWillReceiveProps
componentWillReceiveProps = async nextProps => {
if (nextProps.questObject.length !== 0) {
const authToken = await AsyncStorage.getItem("authToken");
this.props.getProfile(authToken);
}
};
However only this.props.getQuests();
is fired and the 2nd action this.props.getProfile(authToken)
is not being fired.
const mapStateToProps = ({ quest, profile }) => {
const { error, loading, questObject } = quest;
const { profileObj } = profile;
return { error, loading, questObject, profileObj };
};
export default connect(
mapStateToProps,
{ getQuests, getProfile }
)(HomeScreen);
Currently it returns the following error:
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.