首页 > 解决方案 > 将 redux 转换为 redux 工具包

问题描述

在这里反应初学者,通过编码学习,需要一些帮助/建议来将此 Redux 存储转换为 Redux 工具包,这里我使用名为 configureStore 的函数,将其更改为使用来自 '@reduxjs 的'configureStore' 的好方法是什么/toolkit' 这是为了学习,'createRootReducer' 来自我的 reducers.js,它结合了

const createRootReducer = (history) => combineReducers({
articles: articlesReducer,
selection: selectionReducer,

});

将不胜感激任何帮助/建议。我的 store.js:

import { createBrowserHistory } from "history";
import { createStore, compose, applyMiddleware } from "redux";
import thunk from "redux-thunk";
import { routerMiddleware } from "connected-react-router";
import createRootReducer from "./reducers";

export const history = createBrowserHistory();

const storeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;

export default function configureStore(preloadedState) {
  const store = createStore(
    createRootReducer(history),
    preloadedState,
    storeEnhancers(applyMiddleware(routerMiddleware(history), thunk))
  );
  return store;
}

标签: javascriptreactjstypescriptreact-reduxredux-toolkit

解决方案


推荐阅读