Skip to content

Instantly share code, notes, and snippets.

@markodayan
Last active February 14, 2020 13:36
Show Gist options
  • Save markodayan/e32f1f405eed4b04cc7c12515d83584c to your computer and use it in GitHub Desktop.
Save markodayan/e32f1f405eed4b04cc7c12515d83584c to your computer and use it in GitHub Desktop.
Some Information around Redux Store Containers
/* 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