Close the earlier lessons and build this from the brief.
The brief
A Plan today page. The topics come from getTopics() in lib/topics.js.
- Each topic is a checkbox labelled with its title and · 20 min (its minutes).
- Under the list: Nothing picked yet. until something is ticked, then 2 picked · 45 minutes, counting the ticked topics and adding their minutes.
- The topics are loaded in a server component. Only the part that needs state is a client component.
Acceptance checks: tick Server components and Dynamic routes to see 2 picked · 45 minutes, then untick one. The console shows [server] Reading topics from the database once.
Runs with real Next.js on your computer: unzip, then
npm install and npm run dev. Hint 1: the split
Keep page.jsx as it is, a server component that loads the topics. Write a
client TopicPicker that takes topics as a prop and holds the ticked ids in
state.
Hint 2: the totals
Don't store the count or the minutes: work them out from the ticked ids during
render, with filter and reduce.
Show one solution
Runs with real Next.js on your computer: unzip, then
npm install and npm run dev. Check yourself
- What does a server component send to the browser: its code, or its result?
- Why can't a server component pass
onClickto a client component? - Where should a client component read
window, and why?
Completion is saved in this browser only. It does not measure mastery.