Skip to content
Discussion options

You must be logged in to vote

Instead of calling useDispatch in if with isError, pass it to onError callback.

const { mutate, data, error, isError, isSuccess } = useMutation( (val) => signIn(val), { onError: () => dispatch(addAttempt()) } );

The reason: reference of data changes ->useSelector function returns you a new value-> re-renders the component->isError is still true -> dispatch is called agin 🔄

onError is called once - after mutation return error.

There is also reset function from useMutation - but I don't test it in this case.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@TkDodo
Comment options

Answer selected by TkDodo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants