Skip to content

Instantly share code, notes, and snippets.

@shanebdavis
Last active December 2, 2019 08:02
Show Gist options
  • Save shanebdavis/c8e72c11c048030256ddfbe5f1ecb050 to your computer and use it in GitHub Desktop.
Save shanebdavis/c8e72c11c048030256ddfbe5f1ecb050 to your computer and use it in GitHub Desktop.
Client-side-state for todo app (pseudo-react)
let list = [
{ id: 1, text: "clean the house" },
{ id: 2, text: "buy milk" }
];
// REDUCERS
const _addItem = (list, item) => [...list, { ...item, id: uniqueId() }]
const _deleteItem = (list, item) => list.filter(todo => todo.id !== item.id)
// STUBS:
const useList = () => list // React hook
const deleteItem = (item) => null // dispatcher
const addItem = (item) => null // dispatcher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment