Tsallaka zuwa abun ciki
Justice Tech School

A Todo List

Combine state, a list and events. The list lives in state, adding creates a new array and removing filters it. The logic below runs without React.

Example
let todos = [{ id: 1, text: "Learn" }];
const add = (t, text) => [...t, { id: t.length + 1, text }];
const remove = (t, id) => t.filter((x) => x.id !== id);
todos = add(todos, "Build");
todos = remove(todos, 1);
console.log(todos);

Result

[ { id: 2, text: 'Build' } ]

Exercise

Remove an item.

list.(x => x.id !== id)

Quiz Test

Which method removes by condition?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.