0

我正在使用slicesRedux Toolkit 的功能。您可能知道,一个切片action为每个 created返回一个reducer

我想使用该redux-promise-middleware库,对于给定的ACTION_TYPE,它会创建三个可能的新操作:ACTION_TYPE_FETCHINGACTION_TYPE_FULFILLEDACTION_TYPE_REJECTED。从 的角度来看,我该如何处理slices

4

1 回答 1

1

您需要将预期的操作类型添加到 的extraReducers部分createSlice,例如:

// 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) => {}
  }
})
于 2020-05-05T13:53:28.113 回答