Redux — Basics

Lokesh
2 min readJul 2, 2022

Redux is a state management library used to manage the application state in react. It can be used when prop drilling needs to be avoided. If the application is small we can pass the state from the parent component to the child component using the props but what if our application has a lot of children and every child have their own many children. In this, it will become difficult to pass the data from parent to children of any level to solve this problem we use the redux.

Without Redux
With Store

3 Principles of Redux

  1. The state of the whole application is stored in an object within a single store.
  2. The only way to change the state of the store is to emit an action(an object describing what happened with the data changes).
  3. To specify how the state tree is transformed by actions write pure functions. Reducer functions should always be pure functions.

Why reducers should be pure functions?

When we have reducer function as pure if anything is changed in state, the new copy of state is created in redux and returned, this will indicate that something has changed in store’s reducer, But if we do not have a pure function then it will not create a new copy of state and it will update the same object and it will not indicate that something is changed in the redux state.
In Javascript, the basic concept to compare two objects is to deeply compare them.

This was just the basic introduction to redux. Will be discussing the flow in the later coming videos.

--

--