Skip to content

Instantly share code, notes, and snippets.

Last active November 2, 2019 16:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
import React, { useState } from "react";
import { ItemList, NewItem } from "./components/Items";
import "./App.css";
const initialItems = ["Setup basic components", "Add some styling"];
function App() {
// useState hook returns two values. First is the state itself
// and second is a function that we can use to update the state
const [items, setItems] = useState(initialItems);
function handleAddItem(item) {
setItems([...items, item]);
function handleRemoveItem(index) {
const copy = [...items];
copy.splice(index, 1);
return (
<div className="App">
<header className="App-header">
<h2>🚀 ToDo App</h2>
<NewItem add={handleAddItem} />
<ItemList items={items} remove={handleRemoveItem} />
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment