Todo List (Component with Local State)

easy
By FrontendAtlas Editorial · Updated Nov 12, 2026
easy level
React useState for local stateControlled inputsRendering lists with mapEvent handlers for click and change eventsImmutable updates for arrays of objects
Create a local-state todo list: add, toggle, and remove items. Keep input state controlled, generate stable ids, and update the todos array immutably so React can detect changes and re-render correctly.

Requirements

  • Render a Todo List UI as the main component.
  • Provide a text input and an 'Add' button to create new tasks.
  • Render a list of todos with a checkbox and label for each task.
  • When a task is checked, its text should appear with a line-through style.
  • Provide a 'Remove' button for each task.
  • Provide a 'Clear completed' button that removes all completed tasks.

What the checks look for

The checks find elements by listitem, textbox, button "Add", checkbox, button "Remove", button "Clear completed", text "No tasks yet. Add your first one above.". Keep these in your markup.

Expected behavior

  • Typing into the input updates local component state.
  • Clicking 'Add' with non-empty text adds a new todo and clears the input.
  • Checking a todo toggles its completed state and updates the line-through style.
  • Clicking 'Remove' deletes that todo only.
  • Clicking 'Clear completed' removes all todos whose checkbox is checked.
  • The empty state message is shown when there are no todos.

Implementation notes

  • Use useState to manage the input value and the array of todo items.
  • Each todo item should at minimum have id, text, and done fields.
  • Use array methods like map and filter to update the todos immutably.
  • Use a derived boolean to decide when to show the empty state and footer.

Solution idea

Store the current input text and the list of todos in component state using useState. When the user clicks 'Add', trim the input, guard against empty strings, and append a new todo object to the array. Use map to toggle a todo's done flag, and filter to remove a specific todo or all completed todos.