September 2018
Intermediate to advanced
764 pages
20h 6m
English
If mapStateToProps is a function, then the component will subscribe to changes in the store’s state. When a change occurs, the mapStateToProps function will be invoked, and is passed the store’s entire updated state. The function should extract the parts of the state that are relevant to this component, and return them as an object literal. This object literal will then be merged with the props passed to the component and be available in its methods through this.props.
For our LoginForm component, we only care about the loginForm property inside the state, and so replace our current export statement:
export default LoginForm;
With this:
function mapStateToProps (state) { return state.loginForm; } export default connect(mapStateToProps)(LoginForm); ...Read now
Unlock full access