Today the week comes together. You'll read the finished Study Board, add an
error boundary, run and test it on your own computer, extend it, and then build
a different app from a brief.
Runs with Vite on your computer: unzip, then npm install and npm run dev.
Use it first: add a card, try a blank title, move cards along, select one and
rename it, and search.
Where everything lives
The app is organised by role, as most real React projects are:
Folder
Holds
state/
The reducer and the context that serves it
hooks/
Custom hooks
components/
Everything that renders
A tour, day by day
Open the files in this order, and find each idea before reading its
explanation.
Day
Idea
Where
1
The selection is an id, not a copied card
StudyBoard in App.jsx
1
Counts and the search results are computed, not stored
useBoardStats.js, Board.jsx
1
Each card gets a fresh editor through a key
CardDetails.jsx
2
Every change goes through one reducer
state/boardReducer.js
3
The reducer is served through two contexts with checked hooks
state/BoardContext.jsx
4
The form focuses the first problem and returns focus after adding; useId connects labels and errors
AddCardForm.jsx, Field.jsx
5
A custom hook reads the context and works out the stats
hooks/useBoardStats.js
6
Column is wrapped in memo with a stable onSelect, but it never skips a render here: question 3 below asks why
Column.jsx, Board.jsx
7
An error boundary around each column
ErrorBoundary.jsx, Board.jsx: the next lesson
Two design choices to notice
App and StudyBoard are separate components.App only places the
provider. StudyBoard holds the search and selection state, which isn't board
data, so it stays local rather than going into the reducer. Not everything
belongs in context:
BoardProvider takes initialCards. The app never passes it, so it uses
the starter cards. Tests pass their own cards, so each test starts from a known
board. You'll use this in the Project Tests lesson:
You select Try context, then search for draw. The selected card is
hidden by the search. Does the details panel still show it?
Rename Try context to Use context. Which components re-render?
Add console.log("Column rendered", column.title); to Column, then click
a card in Doing to select it. Column is wrapped in memo, and
To do and Done didn't change. How many lines appear?
Check your predictions
Yes. CardDetails looks the card up in all the cards by its id, not in
the search results. The selection and the search are separate pieces of
state, and neither depends on the other:
Everything reading useCards(): Board, CardDetails and Toolbar,
through useBoardStats. AddCardForm doesn't, because it only reads the
dispatch context, which never changes. All three columns re-render too,
including Doing and Done, whose cards didn't change. Question 3
shows why.
Three: Column rendered To do, Doing and Done. memo skips a
render only when every prop is the same as last time. Two props never
are. Board builds visible.filter(...) for each column on every render,
and a new array is a changed prop, even with the same cards in it. And
selectedId goes to every column, so a new selection changes all three.
Since Board only re-renders when the cards, the search or the selection
change, memo(Column) never skips anything here.
It's a realistic mistake: memo looks like it helps, and only a
measurement shows that it doesn't. To make it work, each column would need
an array that stays the same while its cards do (useMemo per column) and a
prop that only changes when its own card is selected, such as
selectedId only for the column that holds it. For three short columns,
that's more code than the renders cost. The honest fix is to remove memo,
and add it back only when the Profiler shows the columns are slow.
Completion is saved in this browser only. It does not measure mastery.