Home > OS >  How to access stores when configureStore has multiple reduces?
How to access stores when configureStore has multiple reduces?

Time:03-16

import { configureStore } from "@reduxjs/toolkit";
import userReducer from "./userSlice";

export default configureStore({
  reducer: {
    user: userReducer,
  },
});
import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { Provider } from "react-redux";
import store from "./redux/store";
import {
  BrowserRouter as Router,
  Switch,
  Route,
  Redirect,
} from "react-router-dom";

ReactDOM.render(
  <React.StrictMode>
    <Router>
      <Provider store={store}>
        <App />
      </Provider>
    </Router>
  </React.StrictMode>,
  document.getElementById("root")
);

The above is how I access the one reducer inside of configureStore.

What if:

export default configureStore({
  reducer: {
    user: userReducer,
    second_reducer: second_reducer,
  },
});

how do I access second_reducer?

CodePudding user response:

Something like this

import { useSelector } from 'react-redux'

const state = useSelector((store) => store.second_reducer.state)
  • Related