![]() |
VOOZH | about |
Redux is a state management library used in JavaScript applications. It stores all application data in a single central store, making the data flow predictable and easy to manage. Redux is especially useful when we need to:
Redux is built using core components like the store, actions, and reducers, which work together to manage and update application state in a predictable way.
Actions are plain JavaScript objects that describe what happened in the application and are the only way to send data to the Redux store. Each action must have a type property, while the remaining fields carry the required data; action creators are functions that generate and return these action objects.
type field defines the kind of action to be performed.Example: The easiest example we can take try is To-do. So we will create two action creators one for adding a task in to-do and for removing.
So, the above two functions are action creators. One is for adding a task and one for removing, and see both have a type which tells what is the purpose of actions creator and they will be used with reducers.
Reducers are pure functions that define how the application state should change in response to an action. They take the current state and an action as input, then return a new updated state without modifying the original one.
Let's create a reducer for our To-do.
combineReducers().The store is the central object in Redux that holds the entire state of the application and manages state updates. It acts as a bridge between actions and reducers, ensuring predictable state management.
Example: Let's create a store for our To-do.