Skip to content

Instantly share code, notes, and snippets.

@melikhov-dev
Created October 27, 2017 19:38
Show Gist options
  • Save melikhov-dev/8ee7fe63bf8cf642f06dd00f8af2181e to your computer and use it in GitHub Desktop.
Save melikhov-dev/8ee7fe63bf8cf642f06dd00f8af2181e to your computer and use it in GitHub Desktop.
const ADD_ITEM = 'ADD_ITEM'
function addItem (item) {
return {type: ADD_ITEM, payload: item}
}
function Items ({items, onClick}) {
return (
<div>
<ul>
{items.map((item) => <li>{item}</li>)}
</ul>
<button onClick={() => onClick('foo')}>
Add foo
</button>
</div>
)
}
connect(
(state) => {
return {
items: state.items
}
},
(dispatch) => {
return {
onClick: (item) => {
dispatch(addItem(item))
}
}
}
)(Items)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment