The watchlist layout
Give the watchlist a heading, a ShowList, and a count that follows the cards.
The app is getting crowded
Here is the watchlist as you left it. Three cards, one already watched.
App both holds the list and draws every card.
ShowList only draws the row
Move the map into /ShowList.js, the same split as Splitting into
files. ShowList receives shows and onToggle,
and maps each show to a ShowCard.
It does not call useState. App still owns the array, and still passes
the handler down as in Passing handlers down.
The page looks the same. Tick The Bear: its pill still appears, because
App still holds the list.
A header that is derived
The heading is My watchlist. The count is not state. During render, read
shows.length and shows.filter((show) => show.watched).length.
Array Methods already covers filter.
Andor starts watched, so the line reads 3 shows · 1 watched. Untick
Andor. The line becomes 3 shows · 0 watched.
Genres on the seed data
Each show already has a genre string for the pill. Add a genres array
that matches it, so a later filter can walk a list. The pill still reads
show.genre.
The cards look the same. The Bear still shows Drama. The extra field sits on the object for later.
Common mistakes
- Storing the count in
useState. That number is a snapshot. Tick a box and the header stays put. Compute it during render fromshows. - Giving
ShowListits own copy of the array. ThenApp's header and the cards disagree. Passshowsdown. - Putting
useStateinShowList. The list lives inApp.ShowListonly draws.
Exercise
The header starts at 3 shows · 1 watched, which looks right. Untick
Andor. Andor's pill goes, but the header still says 1 watched.
The count was stored in state. Derive it from shows during render
instead.
After you untick Andor, the header should read:
3 shows · 0 watched
Hint: filter during render, not useState.