What is Redux

Redux is a JavaScript state container that provides predictable state management. Redux also supports other interface libraries in addition to React. My understanding is to manage data.

There is no relationship between Redux and React. Redux supports React, Angular, Ember, jQuery, and even pure JavaScript. But Redux works best with libraries like React, which allow you to describe interfaces as state functions. Redux uses actions to initiate state changes.

Why did Redux appear

The complex state that JS needs to manage makes it difficult to operate and update, and even causes other problems. The complexity is largely due to the confusion between the concepts of change and asynchronism. Some libraries such as React try to solve this problem by banning asynchronism and direct DOM manipulation at the view layer. React still leaves it up to us to deal with the data in state, which Redux does for us.

Iii. Core Concepts of Redux

To update the data in state, you need to initiate an action. To combine the actions with state, develop some functions (Reducer). Reducer is just a function that receives state and action and returns the new state.

For large applications, you need many of these small functions to manage portions of state separately, and then develop a Reducer call to manage state for the entire application. That’s the whole idea of Redux.

Four, Redux three principles

1. Single data source

The state of the entire application is stored in an object tree that exists in only one store. This has some benefits:

  • This makes homogeneous application development very easy: State from the server side can be serialized and injected into the client side without writing more code.

  • Debugging is also easier: you can save your application’s state locally, speeding up development.

  • Features like undo/redo, which were previously difficult to implement, are now easy to implement.

2. State is read-only

The only way to change state is to trigger an action, which is a generic object that describes events that have occurred.

3. Use pure functions to perform changes

To describe how an action changes the State Tree, you need to write reducers.

More content