Last active
February 14, 2020 13:36
-
-
Save markodayan/e32f1f405eed4b04cc7c12515d83584c to your computer and use it in GitHub Desktop.
Some Information around Redux Store Containers
This file contains hidden or 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
/* We can map things from our Redux stores in App Components: | |
- State | |
- Dispatch | |
----------- */ | |
// reading Redux store state example: | |
const mapStateToProps = (state, ownProps) => { | |
let id = ownProps.match.params.post_id; | |
return { | |
post: state.posts.find(post => post.id === id) | |
}; | |
}; | |
// Dispatch an action from component to store example: | |
const mapDispatchToProps = dispatch => { | |
return { | |
deletePost: id => { | |
dispatch({ type: 'DELETE_POST', id: id }); | |
} | |
}; | |
}; | |
// Component calling methods to interact with Redux store (via react-redux) | |
export default connect(mapStateToProps, mapDispatchToProps)(Post); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment