What is Redux?

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.

Architecture of Redux

The Architecture of Redux

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 immutable an immutable object is an object whose state cannot be modified after its creation; after every update, the reducer returns the new state.

Installation

We use Redux with React. To install Redux, we must first install the redux toolkit by writing the following command on the terminal.

# NPM
npm install @reduxjs/toolkit
# Yarn
yarn 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.

# NPM
npm install redux
# Yarn
yarn add redux

Note: Click here to visit the official documentation of the redux

Pros and Cons of 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

Copyright ©2024 Educative, Inc. All rights reserved