Created
August 28, 2020 23:50
-
-
Save julietaansola/8c98b8c832f34cf7971f79204c9e6dab to your computer and use it in GitHub Desktop.
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 React from "react"; | |
function Task(props) { | |
return <li>{props.task}</li>; | |
} | |
export default Task; |
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 React, { useState } from "react"; | |
import Task from "../Task/index"; | |
function Tasks() { | |
const [tasks, setTasks] = useState([]); | |
const [newTask, setNewTask] = useState(""); | |
function handleClick() { | |
setTasks((tasks) => [...tasks, newTask]); | |
console.log(tasks); | |
} | |
function handleChange(e) { | |
setNewTask(e.target.value); | |
console.log(newTask); | |
} | |
return ( | |
<div> | |
<input type="text" placeholder="create task" onChange={handleChange} /> | |
<button onClick={handleClick}>Add</button> | |
<ul className="taskContainer"> | |
{tasks.map((task, key) => ( | |
<Task key={key} task={task} /> | |
))} | |
</ul> | |
</div> | |
); | |
} | |
export default Tasks; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment