Created
April 22, 2020 00:56
-
-
Save kevinhooke/9e42b4df159bee5deb782c7fd2b94dea to your computer and use it in GitHub Desktop.
react redux : use connect() with mapStateToProps to pass state into Components as props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import {connect} from 'react-redux'; | |
class YourComponent extends Component { | |
constructor(props){ | |
super(props); | |
} | |
render() { | |
return ( | |
<div> | |
Example render of a mapped prop: { this.props.someprop } | |
</div> | |
); | |
} | |
} | |
function mapStateToProps(state){ | |
return { | |
someprop : state.somevaluefromstate, | |
} | |
} | |
export default connect(mapStateToProps)(YourComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment