![]() |
VOOZH | about |
To combine multiple reducers in React JS we have a function called combineReducers in the redux. This basically helps to combine multiple reducers into a single unit and use them.
In React, to combine and implement multiple reducers combineReducers methods are used. It manages multiple reductions and uses them with the defined actions in the redux.
Step 1: Create a React application using the following command:
npx create-react-app exampleStep 2: After creating your project folder i.e. example, move to it using the following command:
cd exampleStep 3: Install the following modules. From the root directory of your project in the terminal, run the following command:
npm i redux react-reduxThe updated dependencies in package.json file will look like:
{
"dependencies": {
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-redux": "^8.1.3",
"react-scripts": "5.0.1",
"redux": "^4.2.1",
"web-vitals": "^2.1.4"
},
}
Example: Make a simple book list application with the help of redux to understand how to combine multiple reducers.
Step to run the application: Run the application using the following command
npm startOutput: Open browser and visit http://localhost:3000/ to see this output