Welcome Guest! (App Version 5.16)

websitnero logo name

What is Redux?

What is Redux?

Redux is a state management tool that is used for libraries which have got concept of state like React. The concept behind redux is that - there should be a 'single global store' that will contain all the data to be used on the view of Front-End.

If we don't use Redux then passing data from one component to another (if they are not direct parent-child) becomes very difficult. For example, what if the 2 components are siblings or not directly related as descendant or parent of one another. So in such scenarios, state management and passing data to multple levels in hierarchy becomes very difficult. So, we use Redux.

Laws of Redux

There are 3 laws that you must follow while implementing redux:

  1. The state of your complete application must be stored (mostly as an object tree) within a single store and therefore your complete application will have - a single source of truth.
  2. Reducer function must always give same output for the same inputs. Here if you make a reducer function and return something like Math.random() * someParam from it, kindly note that each time the output would be different, which would be wrong as per rules of redux.
  3. Reducer function must not change its original inputs (or params passed to it). Here kindly note that Objects and Arrays follow call be Reference (as they only contain pointer to a memory reference) and if inside function their content is modified, after exiting function also, their contents would permanently change (unlike primitive data-types following call-by-value model).
  4. State is read-only or immutable. This means that the Reducer function will not change the original state passed to it (as explained above). What it will do is however, make a copy of the original state and then in this copy make whatever changes are required and then return this copy (rather than the original pointer of state object).
Further Reading

1. Redux Principles

WebsiteNero is highly optimized for learning various website developing technlogies. We try our best to add maximum modules and examples to help learn the concepts clearly and vividly. We try to present all content and examples as simple as we can removing any complexity to hurdle easy understanding. We try best provide you with worthful content, but we cannot guarantee full correctness of all the content on this site. While using this website, you agree to have read and accepted all our terms of use and conditions, cookie, and privacy policy. Copyright, 2013-2018 by websitenero.com. All Rights Reserved.