Home > front end >  what is type of action in createAsyncThunk in redux-toolkit?
what is type of action in createAsyncThunk in redux-toolkit?

Time:02-01

what is a type of signup action with createThunk in redux-toolkit, the signup action type gives me an error, actually I don't know what is type of createThunk parameter type please help me thanks

type ServerError=string

type state = {
userInfo: user;
loading: boolean;
erroeMessage: string;
successMessage: string;
};


const initialState: state = {
userInfo: {
 name: "",
 email: "",
 token: "",
},
loading: false,
erroeMessage: "",
successMessage: "",
};

export const signup: AsyncThunk<
any,
user,
{
 user:object,
 rejectValue: ServerError;
}
> = createAsyncThunk("auth/signup", async (user, { rejectWithValue }) => {
try {
 const { data } = await axios.post(
   "https://api.freerealapi.com/auth/register",
   user
 );
 setCookie('userInfo', JSON.stringify({...user,token:data.token}))
 return {...user,token:data.token}

} catch (error: any) {
 return rejectWithValue(error.response.data.message);
}
});


CodePudding user response:

This payloadCreator parameter is detailed in the documentation. The type is AsyncThunkPayloadCreator:

import {type AsyncThunkPayloadCreator} from '@reduxjs/toolkit';
  •  Tags:  
  • Related