我正在使用Redux Toolkit的slices特性。正如您可能知道的,一个切片为每个创建的reducer返回一个action。
我想使用redux-promise-middleware库,对于给定的ACTION_TYPE,它将创建三个可能的新操作:ACTION_TYPE_FETCHING、ACTION_TYPE_FULFILLED和ACTION_TYPE_REJECTED。从slices的角度来看,我该如何处理这件事?
发布于 2020-05-05 21:53:28
您需要将预期的操作类型添加到createSlice的extraReducers部分,例如:
// could use a predefined action constant if desired:
const actionFetching = "ACTION_TYPE_FETCHING"
const usersSlice = createSlice({
name: "users",
initialState,
reducers: {
// specific case reducers here
},
extraReducers: {
// could use computed key syntax with a separate type constant
[actionFetching ]: (state, action) => {}
// or the actual field name directly matching the type string
ACTION_TYPE_FULFILLED: (state, action) => {}
}
})https://stackoverflow.com/questions/61582886
复制相似问题