I was migrating from Apollo client to Redux toolkit and I am confusing how to use the result(success or error) of API call with createAsyncThunk and call history.push('/') and setSubmitting(false) in my React component.
Example how I did with Formik and Apollo Client:
onSubmit={async (values, { setSubmitting }) => {
signInMutation({
variables: {
email: values.email,
password: values.password,
},
}).then(
(response) => {
if (response.data.signIn.accessToken) {
localStorage.setItem(
AUTH_TOKEN,
response.data.signIn.accessToken,
);
if (response.data.signIn.User.isNew) {
history.push('/welcome-page');
} else {
history.push('/');
}
setSubmitting(false);
}
},
(err) => {
console.log(`error signin ${err}`);
enqueueSnackbar(err.message, {
variant: 'error',
});
setSubmitting(false);
},
);