Skip to content

Instantly share code, notes, and snippets.

@shanebdavis
Last active December 28, 2019 21:33
Show Gist options
  • Save shanebdavis/95223a0fb00b3c0a3cd81d1909a05e31 to your computer and use it in GitHub Desktop.
Save shanebdavis/95223a0fb00b3c0a3cd81d1909a05e31 to your computer and use it in GitHub Desktop.
modular-redux-tutorial redux/index.js part 1 definitions
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