Closed AlexisTercero55 closed 1 year ago
Redux set up based on Installation guide
"dependencies": {
"@reduxjs/toolkit": "^1.9.2",
"bootstrap": "^5.2.3",
"react": "^18.2.0",
"react-bootstrap": "^2.7.2",
"react-dom": "^18.2.0",
"react-redux": "^8.0.5",
"redux": "^4.2.1"
},
"devDependencies": {
"@types/react": "^18.0.27",
"@types/react-dom": "^18.0.10",
"@vitejs/plugin-react": "^3.1.0",
"vite": "^4.1.0"
}
The whole global state of your app is stored in an object tree inside a single store.
The only way to change the state tree is to create an action, an object describing what happened, and dispatch it to the store.
To specify how state gets updated in response to an action, you write pure reducer functions that calculate a new state based on the old state and the action.
import { createStore } from 'redux'
/**
* Reducer - a function that takes a current state value and an
* action object describing "what happened", and returns a new state value.
* A reducer's function signature is: (state, action) => newState
*
* The Redux state should contain only plain JS objects, arrays, and primitives.
* The root state value is usually an object. It's important that you should
* not mutate the state object, but return a new object if the state changes.
*/
function anyReducer(state, action) => newState;
// Create a Redux store holding the state of your app.
// Its API is { subscribe, dispatch, getState }.
let store = createStore(anyReducer);
In a typical Redux app, there is just a single store with a single root reducing function.
As your app grows, you split the root reducer into smaller reducers independently operating on the different parts of the state tree.
This is exactly like how there is just one root component in a React app, but it is composed out of many small components.
Based on Redux Toolkit React Counter App
configureStore
<img src="https://user-images.githubusercontent.com/87354316/219885248-9ac7a70a-c71d-4b2a-bccc-e20eb3b0dded.svg" alt="Redux" height="400"/>