I. what is redux
Redux
is a JavaScript
container for state management. Redux
supports other interface libraries besides being used with React, and its volume is only about 2kb
.
three cores of Redux
- single data source
- the
state of the entire application
is stored in an object tree, and this object tree exists only in the onlystore
.
- the
- State is read-only
- the only way to change state is to trigger & nbsp;
action
, which is a normal object used to describe events that have occurred.
- the only way to change state is to trigger & nbsp;
- use pure functions to perform modifications
- to describe how action changes state tree, you need to write & nbsp;
reducers
.
- to describe how action changes state tree, you need to write & nbsp;
Redux composition
-
State status
- state, ui state, global state returned by the server
-
action event
- is essentially a js object
- needs to include the type attribute
- describes what is going to happen, but does not describe how to update state
-
reducer
- is essentially a function
- response to the action sent
- function takes two parameters, the first initializing state and the second sending action
- must have a return return value
The
-
Store
- maintain the state (status) of the application (state, ui state, global state returned by the server)
- provide getstate method to read state
- used to associate action with reducer
- build store through createStore
- register to listen through subscribe
- dispatch method to send action