What is Redux? Store, Actions, and Reducers Explained for Beginners

From the engineers’ point of view, a huge benefit of Redux is in improving the developer experience. It makes handling complex logic easier by keeping it organized rather than dispersed throughout the app. On top of that, it provides convenient testing and debugging tools that save software engineers a lot of time.

why redux

It is easy to test Redux apps since functions used to change the state of pure functions. 💡 state refers to the object that holds the application data that is shared between components. It’s clear that state management gets messy as the app gets complex. This is why you need a state management tool like Redux that makes it easier to maintain these states. Let’s get a good overview of Redux concepts before considering its benefits.

How One Conditional Can Entangle Your React App

This is in part due to concerns that Redux may be unnecessarily complicated for some applications – some considered it an over-engineered solution to a relatively simple problem. After its launch in 2015, Redux grew in popularity as a simple and lightweight solution for state management when building with React, the dominant front-end framework in the JavaScript ecosystem. However, it can also be used with other JavaScript frameworks and libraries such as jQuery, Angular, or Vue. Based on usage, Redux is the most popular library in the ‘data layer’ category of the latest ‘State of JavaScript’ developer survey. As you can see in the example above, the component does not need to provide any state or method for its children components to share data among themselves.

why redux

Whenever we dispatch an action with a certain type, we need to make sure to have appropriate reducers to handle that action. There can either be one reducer if it is a simple app or multiple reducers taking care of different parts or slices of the global state in a bigger application. The state of the whole application is stored in the form of a JS object tree in a single store as shown below.

Can Redux only be used with React?​

Redux is a very popular open-source library that facilitates state management in applications. It is a cross-platform and open-source library and has taken its inspiration from why redux Facebook’s Flux architecture. It has eliminated the unnecessary complexities that existed in the Flux architecture. While coding Redux, you won’t normally use actions directly.

why redux

Then we increment the noOfItemInCart by 1, update the cart array by adding the new object passed in the action.payload shown below, and then finally return the updated object. So reducers are basically pure JS functions which take in the previous state and an action and return the newly updated state. In the following section, we will dive deep into the core concepts of Redux – the store, actions and reducers. Whenever a user adds an item to the cart, the application has to internally handle that action by adding that item to the cart object. It has to maintain its state internally and also show the user the total number of items in the cart in the UI.

Scroll to Top