React Dojo

Search

Search concepts, exercises and quizzes

practiceintermediate

Todo list with useReducer

A task list with three actions: add, toggle done, and remove. Implement the reducer keeping purity rules: no mutation, each transition returns a new state.


Objectives

  1. 1.Define a reducer with actions: add, toggle, remove
  2. 2.Initial state: { items: [], next: 1 } — next serves as an incremental ID
  3. 3.Each item: { id, text, done }
  4. 4.Add via a form with a text input
  5. 5.Toggle done with a click on the text
  6. 6.Remove with a button per item
your code
Hint

Treat each switch case as a pure function: receives state and action, returns a new object without touching the previous one.

Related concepts

Was this helpful?
Sign in to give feedback