in this code snippet I want to know async and await not working why
this code in my component I am sure that is no errors
const {success, loading, error} = useSelector(
(state) => state.loginReducer
);
const formik = useFormik({
initialValues,
validationSchema,
onSubmit: async (values) => {
await dispatch(login(values));
console.log(success);
},
});
this is the slice
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
import axios from "axios";
const initialState = {
token: localStorage.getItem("token"),
loading: false,
error: null,
success: false,
};
export const login = createAsyncThunk("login/login", async (values) => {
const { data } = await axios.post(
"https://note-sigma-black.vercel.app/api/v1/users/signIn",
values
);
return data;
});
const loginSlice = createSlice({
name: "login",
initialState,
extraReducers: function (builder) {
builder.addCase(login.pending, (state) => {
state.loading = true;
});
builder.addCase(login.rejected, (state, action) => {
state.loading = false;
state.error = action.error.message;
});
builder.addCase(login.fulfilled, (state, action) => {
state.loading = false;
state.token = action.payload.token;
state.success = true;
localStorage.setItem("token", action.payload.token);
});
},
});
export default loginSlice.reducer;
i expect that while i dispatch a promise function async and await should wor