是否可以在应用程序中使用更多减速器

Is it possible to use more reducer in app

是否可以在app中使用更多reducer,我已经创建了几个reducer文件,我想在provider中共享。可能吗?我尝试了很多东西但没有成功,例如:combineReducers.

import { BrowserRouter, Routes, Route} from 'react-router-dom';
import { createStore, combineReducers} from "redux";
//import reducer from "../src/reducer/TestReducer";
import reducerAuthentification from "../src/reducer/ReducerAuthentification"
import TestReducer from "../src/reducer/TestReducer"
import './assets/style/app/App.css';
import './assets/style/app/App.scss';
import React from 'react';

import Accueil from './view/accueil/Accueil';
import Feuillete from './view/patisserie/Feuilletes';
import Footer from './view/footer/Footer';
import Reservation from './view/reservation/Reservation';
import { Provider } from 'react-redux';
import Compte from './view/client/compte/Compte';
const store = createStore(reducerAuthentification);
const store1 = createStore(TestReducer)
// const appReducers = createStore({
//   reducerAuthentification: "",
//   TestReducer: ""
// })

function App() {
  return (
    <Provider store={{store}}>
      <div className="App">
        <BrowserRouter>
          {/* <Navbar/> */}
          <header className="App-header">
            <Navigation/>
          </header>
          <Routes>
            <Route path={"/"} element={<Accueil />}/>
            <Route path={"/les-patisseries/les-feuilletes"} element={<Feuillete />}/>
            <Route path={"/reservation"} element={<Reservation />}/>
            <Route path={"/compte"} element={<Compte />} />
          </Routes>
          <Footer />
        </BrowserRouter>
      </div>
    </Provider>
  );
}

export default App;

您可以按照其文档中所示使用 combineReducers。

https://redux.js.org/api/combinereducers

最佳做法是将所有减速器合并到单独的文件中。
例如:

rootReducer.js:

const rootReducer = combineReducers({
    reducer1: reducerOne,
    reducer2: reducerTwo,
})

export default rootReducer

store.js:

import rootReducer from './rootReducer'

const store = createStore(rootReducer)

Redux createStore 是已弃用的方法,它可以工作,但您应该使用 configureStore 来创建商店。
参见:https://redux-toolkit.js.org/introduction/getting-started