Reputation: 147
I'm new to react and redux. Now I build my first application that is connecting to an api server with redux. In my reducer file I'm setting the new state. My question is how can I access that state value in a component?
Upvotes: 0
Views: 45
Reputation: 726
You need to connect your component to the Redux store via the connect
component, which is provided by Redux. The connect
component requires a function to be provided called mapStateToProps
. This function will tell Redux which items from the Redux state you want in your component.
It will look something like this:
function mapStateToProps(state) {
return { yourStateKey: state.yourStateKey }
}
export default connect(mapStateToProps)(YourComponent)
You can learn more in the appropriate section in the Redux docs.
Upvotes: 2