Last active
December 28, 2019 21:33
-
-
Save shanebdavis/95223a0fb00b3c0a3cd81d1909a05e31 to your computer and use it in GitHub Desktop.
modular-redux-tutorial redux/index.js part 1 definitions
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 { useState, useLayoutEffect } from "react"; | |
import { store } from "./store"; | |
const storeKey = "list"; | |
// DEFINITIONS | |
const getUniqueId = list => | |
list.length > 0 ? Math.max(...list.map(t => t.id)) + 1 : 1; | |
const initialState = [ | |
{ id: 1, text: "clean the house" }, | |
{ id: 2, text: "buy milk" } | |
]; | |
const reducers = { | |
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