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
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.
- React reference: useState (avoiding recreating the initial state)
- React docs: Updating Arrays in State
- MDN: Window.localStorage
- MDN: Storage quotas and eviction criteria
- Vite: Getting Started
Code examples stay in English and run in a sandbox on your device. If you spot a mistake, tell us through the contact page.