![]() |
VOOZH | about |
Before going to the topic "Redux Workflow Features" we should look at the question "What is Redux?"
What is Redux?
"A Predictable State Container for JS Apps". In other words, Redux is a pattern-based library that is used to manage and update the application state. For managing and updating the application state Redux used events known as "action".
Redux has some properties which make it popular some of them are described below:
Let's take an example to understand redux easily. Let's imagine an application like a food app where we can manage the recipe using the Redux Store. For managing the recipe in the application we have some basic methods which help us to do so like:
In Redux workflow is unidirectional. This means it can flow singly only not going to reverse order is possible. Also, it maintains the flow of data in a very efficient manner. As the application has complex programming and works then managing the state also becomes complex until we have management or control over the state of the application. So, for this reason, we have to maintain the state of the application. This can happen in the following steps which are known as the redux workflow.
Steps to workflow in Redux:
So, from these steps, the whole application is updated, reset, modify, and many more operations.
Redux Workflow Features: There are some important features that are used to maintain the workflow of the redux. Which are described below:
As we know that if we have an application that stores something and performs some actions which seem to be changeable we have to make it necessary in the state of the application. For this, we have to perform some actions and this is the only way in Redux. Redux is nothing more than plain JavaScript objects which are holding the information needed for changing the state of the application.
Example of an action object
{
type: 'INCREMENT',
payload: {
Id: 'main',
amount: -100
}
}
A function that creates an action object
function increment(Id, amount) {
return {
type: 'INCREMENT',
payload: {
ID,
amount
}
};
};If an action is sent to the store, then the store needs to change the state according to the action. For this, it calls known Reducers, It takes the current state of the application and returns the action that needs to be performed on the state.
In other words, we can say that reducers are function that takes two parameters like current state and action. And return to the next state. Syntax of the function:
function callNextState(state, action) {
...
return nextState;
}
Note- Reducers never modify the state; they always create a copy of the needed changes in the state.
The middleware is a test feature of Redux. Because it tests the actions before they reach to store. Middleware can change the actions, create more actions, etc. Middleware uses the dispatch() function. It is a more powerful tool in Redux.
Redux has a single store for the whole application. But the store doesn't have any user logic. So, when the actions are encountered at the store. Store send them to the middleware. Middleware tests the actions and makes necessary changes and then sent them to the reducers. Reducers take state action and return to the next state. After all this store receives a that causes a change to the state. The store notifies all the listeners that a change to the state has occurred. Then the various parts will be updated as the application have to modify.
From all these things the workflow happened.