Skip to content

Instantly share code, notes, and snippets.

@marg51
Last active January 22, 2017 13:35
Show Gist options
  • Save marg51/2f44dee22caf75f51b9ac28e8afadd88 to your computer and use it in GitHub Desktop.
Save marg51/2f44dee22caf75f51b9ac28e8afadd88 to your computer and use it in GitHub Desktop.
Medium — Decorators
// example from http://redux.js.org/docs/basics/UsageWithReact.html
// annotated and simplified for this Medium story
import { connect } from 'react-redux'
import TodoList from "./todo-list"
const mapStateToProps = (state) => {
return {
todos: state.todos // bound to `this.props.todos`
}
}
const mapDispatchToProps = (dispatch) => {
return {
onTodoClick: (id) => { // bound to `this.props.onTodoClick`
dispatch(toggleTodo(id))
}
}
}
const VisibleTodoList = connect(
mapStateToProps,
mapDispatchToProps
)(TodoList)
export default VisibleTodoList
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment