Redux JointReducers 和 Redux-toolkitConfigureStore 之间有什么区别

发布于 2025-01-10 18:50:25 字数 302 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

朦胧时间 2025-01-17 18:50:25

它们是完全不同的东西。

如果reducer选项是切片reducer的对象,例如{ users: usersReducer, posts: postsReducer }configureStore将自动创建根reducer通过将此对象传递给 Redux combineReducers 实用程序。请参阅源代码

  if (typeof reducer === 'function') {
    rootReducer = reducer
  } else if (isPlainObject(reducer)) {
    rootReducer = combineReducers(reducer)
  } else {
    throw new Error(
      '"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers'
    )
  }

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 Redux combineReducers utility. See source code

  if (typeof reducer === 'function') {
    rootReducer = reducer
  } else if (isPlainObject(reducer)) {
    rootReducer = combineReducers(reducer)
  } else {
    throw new Error(
      '"reducer" is a required argument, and must be a function or an object of functions that can be passed to combineReducers'
    )
  }

RTK configureStore setup the redux store configuration, not only reducer, 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文