Introducing Redux
Redux is a very popular library that many developers use to help write their React applications. On its GitHub repo, Redux bills itself as a predictable state container for JavaScript apps. Rather than having each component manage its own independent state, Redux proposes that your entire React application is governed by one single state. This single state is then proliferated through each component and allows the majority of your app's logic to live in reusable functions.
The three principles of Redux
You can describe Redux by referring to three key principles regarding the state: it needs to be the single source of truth for your application, be read-only, and be modifiable only by pure functions.
Single state tree
In Redux, rather than having each component manage its own state, we deal with one single-state tree that contains all the logic in our application. For example, for the Tasks
app we built in the first two chapters, you can visualize it as follows:
{ cellExpanded...