Skip to content

React Project for Beginners: Build a To-do App That Saves to localStorage

NeedMyTools Academy

Sign in free to read the full lesson

Sign in or create a free account

Free forever. No card, no paywall.

This project brings every lesson of the course into one small but complete app: a to-do list that remembers your tasks after you close the page. You will plan the data first, then build the parts one by one: a form with a controlled input, a list rendered with map and stable keys, buttons that tick and delete tasks without mutating state, a line that counts what is left, and finally saving to the browser with localStorage. The finished app is under 80 lines of React, and every line uses something you have already learned. The exercise at the end asks you to write the parts that make it work and remember.

Quick answer

Build a React to-do app in five steps. Keep the tasks as an array of objects { id, text, done } in state. Add tasks from a controlled form with onSubmit, creating a new array with the spread syntax. Render the list with map and key={todo.id}. Toggle with map and delete with filter, never push or splice. To save, read the list once with a lazy initial value, useState(() => loadTodos()), and write it whenever it changes with useEffect(() => saveTodos(todos), [todos]), wrapping localStorage in try and catch because browsers can block it.

60 min read and practice · Content checked on 24 November 2026

In this lesson you will

  • Plan the state of a small app before writing components
  • Add, toggle and delete list items without mutating state
  • Load saved data with a lazy initial state and save it with an effect
  • Handle blocked or broken storage safely

Plan the data first

Before any JSX, decide what the app must remember. Each task needs text, whether it is done, and an id that never changes, so React can key the list and you can find a task to update. That gives an array of objects: { id: "k3", text: "Buy dates", done: false }. The text typed into the box is separate state, because it is not a task yet. Everything else is derived: the number of tasks left is todos.filter(t => !t.done).length, so it is calculated during render and never stored.

Next, list the actions: add a task, tick or untick it, delete it, and clear the finished ones. Each action becomes one small function in the component that owns the state, and each returns a new array: [...todos, task] to add, todos.map(...) to change one item, todos.filter(...) to remove. With one component owning everything, this app does not need context. If it grew, for example with a separate header showing the count, you would lift state or add context exactly as in the previous lesson.

Sign in free to read the full lesson

You are reading the free preview. Create a free account (it takes one minute, no password) to unlock the rest of this lesson and track your progress.

Unlocks after sign-in:

  • 3 more sections with live code examples
  • Common mistakes to avoid
  • Hands-on coding exercise with automatic checks
  • Practice quiz and the graded lesson test
Sign in or create a free account

Free forever. No card, no paywall.

Questions people ask

Why does saving not work in the playground?

The examples run in a sandboxed frame with no access to this site’s storage, for your safety. The browser blocks localStorage there, so the app falls back to memory. Save the code as an HTML file and open it, and saving works.

How much data can localStorage hold?

Usually about 5 MB per site in current browsers, which is plenty for settings and small lists. For large data or files, look at IndexedDB, or store the data on a server.

How do I sync the to-do list between my phone and my computer?

localStorage lives in one browser on one device. To sync, save the tasks on a server through an API, usually with a sign-in, and load them with fetch in an effect as in the effects lesson.

How do I run this React app on my own computer?

Install Node.js, run npm create vite@latest and choose React, then move the TodoApp component and the storage helpers into src/App.jsx. Run npm run dev to see it, and npm run build to make files you can publish.

How do I get the free React certificate?

Sign in to the Academy, pass the short graded test after each lesson and module, submit this project exercise, and pass the final exam. The certificate has an id that anyone can verify on this site.

Sources

Facts in this lesson were checked against these official pages on 24 November 2026.

Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.