首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Redux Toolkit中使用Redux Promise Middleware with slices?

如何在Redux Toolkit中使用Redux Promise Middleware with slices?
EN

Stack Overflow用户
提问于 2020-05-04 07:16:07
回答 1查看 450关注 0票数 0

我正在使用Redux Toolkit的slices特性。正如您可能知道的,一个切片为每个创建的reducer返回一个action

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-05 21:53:28

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

代码语言:javascript
复制
// 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) => {}
  }
})
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61582886

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档