Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 39 ยท Projects and Practice

Project: A Todo App with Stores and Filters

Build a complete SolidJS todo app step by step: a store with actions, derived counts with createMemo, filters, inline editing and a clean component structure.

Time to combine what you learned in this track. You will build a todo app with adding, completing, editing, deleting, a filter (all, active, done) and live counts. It exercises stores, global state patterns, memos and control flow, and it is small enough to read in one sitting.

The live examples load Solid from a CDN and use the html tagged-template helper, which is JSX without a build step. In a real project (npm create solid), you would write the same logic with JSX in .tsx files. The reactivity is identical, and the JSX version of the central component is shown read-only below.

Plan

flowchart LR
  S["todoStore: state + actions"] --> M["memos: visible, remaining"]
  M --> V["Views: input, list, footer"]
  V -- "events" --> S

One store owns the data. Memos derive what to show. Views only read and call actions.

Design rules for the project:

  1. One source of truth: a store with todos and filter.
  2. Actions, not setters: components call addTodo, toggleTodo, editTodo, removeTodo, clearCompleted.
  3. Derived values are memos: visibleTodos and remaining are never stored, only computed.

Step 1: the store and actions

Start with the logic alone, before any UI. This also makes it testable, like in the testing lesson.

Step 1: the store, actions and derived values

Check what happened: the blank title was ignored, filters changed the visible list but not the data, and remaining always counted the unfinished items. All the rules live in the actions, so any UI built on top stays simple.

Step 2: the components

The app splits into four small components, each reading only what it needs:

  • NewTodo: an input that calls addTodo on Enter.
  • TodoItem: a checkbox, a label that becomes an input on double-click, and a delete button.
  • TodoList: a For over visibleTodos().
  • Footer: the remaining count and filter buttons.

Here is the central part in JSX, as you would write it in a real project:

TSX
function TodoItem(props: { todo: Todo }) {
  const [editing, setEditing] = createSignal(false);

  const finish = (e: Event) => {
    const value = (e.currentTarget as HTMLInputElement).value;
    value.trim() ? editTodo(props.todo.id, value) : removeTodo(props.todo.id);
    setEditing(false);
  };

  return (
    <li classList={{ done: props.todo.done, editing: editing() }}>
      <input type="checkbox" checked={props.todo.done}
             onChange={() => toggleTodo(props.todo.id)} />
      <Show when={!editing()} fallback={
        <input value={props.todo.title} autofocus onBlur={finish}
               onKeyDown={(e) => e.key === "Enter" ? finish(e) : e.key === "Escape" && setEditing(false)} />
      }>
        <span onDblClick={() => setEditing(true)}>{props.todo.title}</span>
      </Show>
      <button aria-label="Delete" onClick={() => removeTodo(props.todo.id)}>x</button>
    </li>
  );
}

Notice the small details that make it feel right: Enter saves and Escape cancels, an empty edit deletes the item, and the delete button has an accessible label.

Step 3: the whole app

Step 3: the finished todo app

Try everything: add items, complete some, double-click to edit, filter, clear the completed ones. Use the browser's dev tools to watch the DOM: when you toggle a todo, only its class and checkbox change; the other rows and the input are untouched.

Extending the project

Pick any of these as practice; each uses a technique from this track:

  1. Persistence: save the todos to localStorage in an effect and load them at start (lesson).
  2. Undo: wrap the store in the history helper from the same lesson.
  3. Server sync: replace the store's initial data with a resource, and make toggleTodo optimistic with rollback (async patterns).
  4. Routing: use /active and /done routes instead of the filter field, with useParams.
  5. Tests: write tests for the actions with createRoot and for TodoItem with Testing Library.
  6. Accessibility: a live region announcing "2 items left", focus management after deleting.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why are visibleTodos and remaining memos instead of stored fields?

    Derived data should be computed from the single source of truth.
  2. 2. Why does the app expose actions such as toggleTodo instead of the raw setter?

    Centralizing changes keeps components simple and the data valid.
  3. 3. What happens in the DOM when you toggle one todo?

    Fine-grained reactivity updates the class and checkbox of that one row.
  4. 4. Which key cancels an inline edit in this app?

    Enter saves the new title, Escape leaves editing mode without saving.

Summary

  • Keep one store with named actions, and derive what you display with memos.
  • Split the UI into small components that read from the store and call actions.
  • Details such as Enter/Escape, empty-edit deletion and labels make a todo app feel finished.
  • The same structure scales to persistence, undo, server sync and routing.

Next: Project: A Live Search with Debounce and Suspense