configureStore有多个reduce时如何访问store?
How to access stores when configureStore has multiple reduces?
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")
);
以上是我如何访问configureStore中的一个reducer。
如果:
export default configureStore({
reducer: {
user: userReducer,
second_reducer: second_reducer,
},
});
如何访问 second_reducer?
像这样
import { useSelector } from 'react-redux'
const state = useSelector((store) => store.second_reducer.state)
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")
);
以上是我如何访问configureStore中的一个reducer。
如果:
export default configureStore({
reducer: {
user: userReducer,
second_reducer: second_reducer,
},
});
如何访问 second_reducer?
像这样
import { useSelector } from 'react-redux'
const state = useSelector((store) => store.second_reducer.state)