Created
December 28, 2019 23:43
-
-
Save shanebdavis/aab139c8b469ba957a9ed931ca6cf246 to your computer and use it in GitHub Desktop.
modular-redux-tutorial with hooks-for-redux
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
import { useRedux } from "hooks-for-redux"; | |
const getUniqueId = list => | |
list.length > 0 ? Math.max(...list.map(t => t.id)) + 1 : 1; | |
export const [useList, { addItem, deleteItem }] = useRedux( | |
"list", | |
[ | |
{ id: 1, text: "clean the house" }, | |
{ id: 2, text: "buy milk" } | |
], | |
{ | |
addItem: (list, item) => [...list, { ...item, id: getUniqueId(list) }], | |
deleteItem: (list, item) => list.filter(todo => todo.id !== item.id) | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment