You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A JS library for predictable and maintainable global state management
Redux keywords
Reducer
Action
Action creator
Action Type
Acion Payload
Dispatch
Store
Redux Dataflow
Let's suppose create a few characters to understand redux flow.
KING which is basically UI.
SERVENT which is called Action creator
POSTMAN, which takes action and dispatched (delivered) to the BANK
BANK MANAGER, is a reducer
BANK, is a king account store.
Scenario 1 - Depositing the money
KING wants to deposit some amount into his account. But he can't go to bank directly. So he tells to one his servant, to deposit the amount in the bank.
SERVENT receives the order from the KING, then he writes an evelop and handover to POSTMAN to deposit the amount.
In the envelop, he write two things,
Deposit
Amount of $500
POSTMAN receives the evelops from the servant and dispatched to the bank.
BANK MANAGER receives the envelop and update the account of the king and send backs to the KING.
Scenario 2 - Withdrawing the money
KING wants to withdraw some amount from his account. But he can't go to bank directly. So he tells to one his servant, to withdraw the amount from the bank.
SERVENT receives the order from the KING, then he writes an evelop and handover to POSTMAN to withdraw the amount.
In the envelop, he write two things,
Withdraw
Amount of $100
POSTMAN receives the evelops from the servant and dispatched to the bank.
BANK MANAGER receives the envelop and update the account of the king and send backs to the KING.
Reducer
account object is have accountReducer.
users object is have usersReducer.
Adding package in Project
Create a folder with name of mkdir ~/app-name && cd app-name
Install Vite
npm create vite@latest . && npm i
npm install redux react-redux
Create a folder with name of store or state or reducer in the root src/[name] folder (ALL REDUX LOGIC IN THIS FOLDER).
Inside the store folder, create a reducer folder.
Now, create a accountReducer.js in reducer folder.