Redux
https://redux.js.org/
https://cn.redux.js.org/
store.getState()
https://redux.js.org/api-refe…
This function returns to get the lateststate
It will not be triggered by the outside world.
store.subscribe(listener)
https://redux.js.org/api-refe…
This function returns a functionunsubscribe
。
After this function is executed, as long asstore
Ofstate
Any change, functionlistener
It will be executed. Until the functionunsubscribe
Is called.
At present, there is no official monitoringstate
Part of the way to change.
store.dispatch(action)
https://redux.js.org/api-refe…
After this function is executed, thestate
Byaction
Members mentioned will bereplace。
This function returnsaction
。
react-redux
https://github.com/reduxjs/re…
https://segmentfault.com/a/11…
// react-redux
connect([mapStateToProps], [mapDispatchToProps], [mergeProps], [options])
mapStateToProps(state)
mapDispatchToProps(dispatch, ownProps)
functionmapStateToProps(state, ownProps)
This function canstate
(or its members) are bound to the component as props.ownProps
Is the props of the component itself.
Once the props change, the component will re render.
functionmapDispatchToProps(state, ownProps)
This function providesdispatch
So that components can be created for changestate
The props (function) of.ownProps
Is the props of the component itself.
This function is related tostore.dispatch
The only advantage is that if the component definition is not in the entry file (such asindex.js
)This method can be avoidedimport
Global in the entry filestore
. So, this function doesn’t really make much sense.