Project: Todo App
Combine state, lists and forms into a small app.
Example
function Todos() {
const [text, setText] = useState("");
const [todos, setTodos] = useState([]);
function add(e) {
e.preventDefault();
setTodos([...todos, { id: Date.now(), text, done: false }]);
setText("");
}
return (
<>
<form onSubmit={add}>
<input value={text} onChange={(e) => setText(e.target.value)} />
</form>
<ul>{todos.map((t) => <li key={t.id}>{t.text}</li>)}</ul>
</>
);
}Exercise
Add an item.
setTodos([...todos, ])
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.