Redux JointReducers 和 Redux-toolkitConfigureStore 之间有什么区别
import { configureStore } from "@reduxjs/toolkit";
import testSlice from "./testSlice";
import {combineReducers} from "redux";
const rootReducer = combineReducers({test: testSlice})
export const store = configureStore({
reducer: rootReducer,
});
哪一个更好?出于性能和使用目的。哪个好用?
import { configureStore } from "@reduxjs/toolkit";
import testSlice from "./testSlice";
import {combineReducers} from "redux";
const rootReducer = combineReducers({test: testSlice})
export const store = configureStore({
reducer: rootReducer,
});
Which one is better? for performance and use purpose. Which is good to use?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们是完全不同的东西。
如果
reducer
选项是切片reducer的对象,例如{ users: usersReducer, posts: postsReducer }
,configureStore
将自动创建根reducer通过将此对象传递给 ReduxcombineReducers
实用程序。请参阅源代码RTK
configureStore
设置 redux 存储配置,不仅包括reducer
,还包括中间件、开发工具、预加载状态和增强器。Redux
combineReducers
辅助函数将具有不同归约函数的对象转换为单个归约函数They are totally different things.
If the
reducer
option is an object of slice reducers, like{ users: usersReducer, posts: postsReducer }
,configureStore
will automatically create the root reducer by passing this object to the ReduxcombineReducers
utility. See source codeRTK
configureStore
setup the redux store configuration, not onlyreducer
, but also middlewares, dev tools, preloaded state, and enhancers.The Redux
combineReducers
helper function turns an object whose values are different reducing functions into a single reducing function