Skip to content

Instantly share code, notes, and snippets.

@jogilvyt
Created January 25, 2021 14:44
Show Gist options
  • Save jogilvyt/84e5f6436c4b037f826692fce7b7a23d to your computer and use it in GitHub Desktop.
Save jogilvyt/84e5f6436c4b037f826692fce7b7a23d to your computer and use it in GitHub Desktop.
import { useState } from "react";
import { v4 as uuid } from "uuid";
import "./ToDo.css";
import ToDoList from "./ToDoList";
import Form from "./Form";
const ToDo = () => {
const [todos, setTodos] = useState([{ id: uuid(), value: "A to do item" }]);
const handleSubmit = inputValue => {
setTodos([...todos, { id: uuid(), value: inputValue }]);
};
const handleDelete = id => {
const filteredTodos = todos.filter(todo => todo.id !== id);
setTodos(filteredTodos);
};
return (
<div className="wrapper">
<h2>Things to do:</h2>
<ToDoList todos={todos} handleDelete={handleDelete} />
<Form handleSubmit={handleSubmit} />
</div>
);
};
export default ToDo;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment