View on GitHub

marymafa.github.io


layout: post title: redux date: 2018-02-20 —

Redux

Is a predictable state container for JavaScript apps. It helps developers write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. Additionally, it provides improvements to the developer experience, like live code editing combined with a time traveling debugger.

Redux can be used together with React, or with other view libraries. The Redux file size is small, 2kB, including dependencies

How Does Redux Work?

Redux is astonishingly simple. It uses a function called a reducer (a name derived from the JavaScript reduce method) that takes two parameters: An action, and a next state.

The reducer has access to the current (soon to be previous) state, applies the given action to that state, and returns the desired next state.Reducers are designed to be pure functions; meaning, they produce no side effects. If you pass the same input values to a reducer 100 times, you will get the exact same output value 100 times. Nothing weird happens. They are completely predictable. As someone with a prominent “NO SURPRISES” sticky note on my monitor, this is a wonderful idea to contemplate.Reducers do not store state, and they do NOT mutate state. They are passed state, and they return state.