加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – 我们应该使用多个联合减速器吗?

发布时间:2020-12-15 16:19:50 所属栏目:百科 来源:网络整理
导读:我有三个减速器 家 上市 细节 我有三个以上的联合减速机.但我想将项目结构划分为多个减速器.在项目中使用多个联合减速器是一个好习惯吗? 解决方法 是的,您可以在您的应用程序中使用多个combineReducers,您可以在顶层将Reducer Home,Listing和Detail组合在一
我有三个减速器

>家
>上市
>细节

我有三个以上的联合减速机.但我想将项目结构划分为多个减速器.在项目中使用多个联合减速器是一个好习惯吗?

解决方法

是的,您可以在您的应用程序中使用多个combineReducers,您可以在顶层将Reducer Home,Listing和Detail组合在一起,甚至将每个单独的reducer拆分为多个并将它们合并为一个.

根据Redux docs:

You may call combineReducers at any level of the reducer hierarchy.
It doesn’t have to happen at the top. In fact you may use it again to
split the child reducers that get too complicated into independent
grandchildren,and so on.

关于combineReducer的更多描述:

As your app grows more complex,you’ll want to split your reducing
function into separate functions,each managing independent parts of
the state.

The combineReducers helper function turns an object whose values are
different reducing functions into a single reducing function you can
pass to createStore.

The resulting reducer calls every child reducer,and gathers their results into a single state object. The shape of the state object matches the keys of the passed reducers.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读