Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 39 ยท Projects and Practice

Practice: SolidJS Challenges

Ten SolidJS exercises on signals, memos, stores, context, resources and control flow, each with a self-checking solution you can run and modify in the browser.

Reading is not the same as writing. This final lesson gives you ten small challenges that revisit the whole track. Each one states a goal, a hint and a runnable solution with checks: the examples print PASS or FAIL lines using a tiny test helper, so you can edit them, break them on purpose and see what the checks catch.

Try each challenge before reading its solution. Open the editor, delete the solution and write your own until the checks pass.

How the checks work

Every example uses the same two helper functions, test(name, fn) and expect(a).toBe(b), similar to the stand-in runner in the testing lesson. Reactive code is created inside createRoot, so effects and memos have an owner.

Part 1: reactive logic

Challenge 1: A clamped counter. Create a signal count and an increment function that never lets the value exceed a maximum. Hint: use the updater form of the setter.

Challenge 2: A derived summary. Given a signal of prices, derive total, average and a boolean isExpensive (average above 50) with memos. Hint: three memos, one reading another.

Challenge 3: A shopping store. Build a store of { items: [] } with add(name, price) that increases the quantity of an existing item, and totalPrice(). Hint: path syntax with a predicate.

Challenge 4: An effect with cleanup. An effect that starts a timer for each new value of a signal and clears the previous timer. Count how many timers fire. Hint: onCleanup.

Solutions 1 to 4, with checks

Part 2: components and control flow

Challenge 5: A toggle with a derived label. A component with a button that toggles on and off and shows "ON" or "OFF". Hint: a signal, and the label as a function in JSX.

Challenge 6: A filtered list. A component that takes a list and a text field and shows only the items containing the text (case-insensitive), or "No matches" if none. Hint: For inside Show with a memo.

Challenge 7: A context counter. A provider that exposes count and increment; two separate child components that read and change it. Hint: createContext, a custom hook that throws without the provider.

Solutions 5 to 7, with checks on the DOM

Part 3: async and architecture (think and sketch)

These three are best done on paper or in your editor, then compared with the lessons.

Challenge 8: A resource with a retry. Load data with createResource, show "Loading...", an error message with a Retry button, and the data. Which two components do you need besides createResource? (See Suspense and ErrorBoundary.)

Challenge 9: Optimistic delete. Delete an item from a list immediately, call the server, and restore the item at its original position if the server fails. Which of the two, mutate on a resource or a store action, would you use, and how do you remember the position? (See async patterns.)

Challenge 10: Route design. Design the file tree of a SolidStart blog with a post list, post page, tag page, admin area with layout, and a 404. Which file holds each query, and which routes need preload? (See file-based routing and route data.)

A sketch for challenge 10:

Text
src/routes/
  index.tsx                 # post list
  blog/[slug].tsx           # post page, preload: getPost(params.slug)
  tags/[tag].tsx            # posts with a tag
  admin.tsx                 # admin layout (auth check via query)
  admin/index.tsx
  admin/posts/[id].tsx      # editor; save is an action that revalidates getPost
  [...404].tsx
src/lib/queries.ts          # getPosts, getPost, getPostsByTag ("use server")

Where to go next

You now know the core of Solid: signals, effects, memos, control flow, stores, context, resources, Suspense, routing and testing. To keep growing:

  • Rebuild an app you already know (a notes app, a weather dashboard) in Solid and compare it with the original.
  • Read the source of a small Solid library; the reactive core is only a few hundred lines.
  • Add SolidStart, a database and authentication, and deploy it.
  • Revisit the track overview and fill in any chapter you skimmed.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. Why do the exercise checks create reactive code inside createRoot?

    Computations need an owner for cleanup; the root provides one and dispose() ends it.
  2. 2. In challenge 4, which call makes sure earlier timers do not fire?

    Cleanup runs before the effect runs again, cancelling the timer created by the previous run.
  3. 3. How does the context hook in challenge 7 help when the provider is missing?

    useContext returns undefined without a provider, so the hook checks and throws early.

Summary

  • Practice is the fastest way to make signals, memos, stores, context and control flow automatic.
  • Self-checking examples make it easy to experiment: change the code and watch which checks fail.
  • Async and routing topics are best practiced by designing and sketching, then building.
  • Keep building: a real app in Solid, then SolidStart with a database, is the natural next step.

Next: Back to the SolidJS track