Redux is an open-source Javascript library that acts as a storage space. It stores the state of all the variables. It helps to create apps that behave consistently across all users. It also helps to test and debug the application to make it traceable at any step.
Many state management tools work with react, but Redux is React’s most popular and widely used tool. It is very lightweight at 2kb, including all the dependencies.
Store: It is where we store the entire traceback route of the state. Consider it as the mind of the Redux.
Action: It creates a new pure object that stores the information of the events. It includes types of action, location, time, and coordinates of occurrences.
Reducer: It reads from the actions. Then It updates the states of the app and returns a new state from the initial one.
Redux's every state is
We use Redux with React. To install Redux, we must first install the redux toolkit by writing the following command on the terminal.
# NPMnpm install @reduxjs/toolkit# Yarnyarn add @reduxjs/toolkit
Note: To learn more about redux toolkit click here.
After successfully executing the above command, we now install the redux core library as a package.
# NPMnpm install redux# Yarnyarn add redux
Note: Click here to visit the official documentation of the redux
Pros | Cons |
It increases state predictability. | The design restriction as redux is very rigid to implement. |
It's easy to maintain as it separates the business logic from the frontend code. | The complexity of logic and code increases. |
It optimizes the performance of apps. | It uses excessive memory. |
It prevents the re-rendering of the user interface. | It lacks encapsulation. |
Free Resources