当fetchUserById()
被创建时,它的输出响应被定义。
const fetchUserById = createAsyncThunk<{user: UserInterface, id: number}, number>(
'users/fetchByIdStatus',
async (userId) => {
const response = await userAPI.fetchById(userId)
return {user: response.data, id: userId}
}
);
const userSlice = createSlice({
name: "users",
initialState: [],
reducers: {},
extraReducers: (builder) => {
builder.addCase(fetchUserById.pending, (state, { payload }) => {
// how I configured custom value for this payload?
// I need to send the user id.
});
builder.addCase(fetchUserById.fulfilled, (state, {payload}) => {
/**
* @var {UserInterface} user
* @var {number} id;
*/
const {id, user} = payload;
state[id].loading = false;
state[id].user = user;
});
},
});
字符串
但是,当操作处于“挂起”状态时,我如何定义响应?
1条答案
按热度按时间mnemlml81#
传入
createAsyncThunk
的arg在action.meta.arg
中也是可用的。所以在你的例子中,你可以像这样引用它:字符串