Created
October 27, 2017 19:38
-
-
Save melikhov-dev/8ee7fe63bf8cf642f06dd00f8af2181e to your computer and use it in GitHub Desktop.
This file contains 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
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