当前位置 : 主页 > 网页制作 > React >

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

来源:互联网 收集:自由互联 发布时间:2021-06-15
我有三个减速器 家 上市 细节 我有三个以上的联合减速机.但我想将项目结构划分为多个减速器.在项目中使用多个联合减速器是一个好习惯吗? 是的,您可以在您的应用程序中使用多个
我有三个减速器

>家
>上市
>细节

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

是的,您可以在您的应用程序中使用多个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.

网友评论