redux-toolkit 中 createAsyncThunk 的动作类型是什么?
what is type of action in createAsyncThunk in redux-toolkit?
什么是redux-toolkit中createThunk的注册操作类型,注册操作类型给我一个错误,实际上我不知道createThunk参数类型是什么类型请帮助我谢谢
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);
}
});
此payloadCreator
参数详见the documentation。类型是 AsyncThunkPayloadCreator
:
import {type AsyncThunkPayloadCreator} from '@reduxjs/toolkit';
什么是redux-toolkit中createThunk的注册操作类型,注册操作类型给我一个错误,实际上我不知道createThunk参数类型是什么类型请帮助我谢谢
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);
}
});
此payloadCreator
参数详见the documentation。类型是 AsyncThunkPayloadCreator
:
import {type AsyncThunkPayloadCreator} from '@reduxjs/toolkit';