FrontendInterviews.dev

Loading problem…

117. Todo List

Easy•
Acceptance: 66.00%
•
🔓3/3 Pro unlocks today

Build a Todo List component in React that allows users to add, remove, and toggle todo items.

Requirements

1. Add Todo Items

  • Input field to enter new todo text
  • Button or Enter key to add todo
  • Each todo should have a unique ID

2. Display Todos

  • Show list of all todos
  • Display todo text
  • Show completion status (checked/unchecked)

3. Toggle Completion

  • Click checkbox or todo item to toggle completion
  • Visual indication of completed todos (strikethrough, different styling)

4. Remove Todos

  • Delete button for each todo
  • Remove todo from the list

5. Data Structure

interface Todo {
  id: number;
  text: string;
  completed: boolean;
}

Example Usage

// Initial state
const todos = [
  { id: 1, text: 'Learn React', completed: false },
  { id: 2, text: 'Build Todo App', completed: true },
];

Constraints

  • Each todo must have a unique ID
  • Handle empty input (don't add empty todos)
  • Use controlled components for input
  • Maintain todo list state