62
rated 0 times
[
67]
[
5]
/ answers: 1 / hits: 10984
/ 3 Years ago, sat, may 15, 2021, 12:00:00
How to reject properly with createAsyncThunk
. I have an asynchronous function that checks whether a mail address already exists or not. The response of the function is an empty string if there is no registered mail address and the user object of the registered user if the user exists.
export const checkIfEmailExists = createAsyncThunk(
"user/checkIfEmailExists",
async (mail) => {
const response = await mailExists(mail).promise();
if (response.user && response.user.length > 0) {
reject();
} else {
resolve();
}
}
);
In both cases the data comes back and no error occurs. How do I reject the createAsyncThunk
in such a case?
More From » redux