Close the earlier lessons and build this from the brief. The starter passes
showMinutes from App through Board and Column to CardItem.
The brief
Replace the drilling with a preferences context:
- A
Preferences.jsxfile with aPreferencesProviderthat holds{ showMinutes: true, compact: false }in a reducer, with the actionsminutes_toggledandcompact_toggled. - State and dispatch in separate contexts, read through two custom hooks,
usePreferences()andusePreferencesDispatch(). Each throws a clear error when used outside the provider. - A
Toolbarcomponent with two checkboxes, Show minutes and Compact. Compact cards have less padding. BoardandColumnno longer mention any preference.
Acceptance checks:
- Unticking Show minutes hides every card's minutes.
- Rendering
Toolbaroutside the provider shows your error message in the console. - No preference props remain in
Board.jsxorColumn.jsx.
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Hint 1: the shape
It's the board-context pattern with different state: createContext(null)
twice, a provider with useReducer, and two hooks that check for null.
Hint 2: compact styling
An inline style is enough: style={compact ? { padding: "0.15rem 0.5rem" } : undefined}
on the card's <li>.
Show one solution
Runs with Vite on your computer: unzip, then
npm install and npm run dev. Check yourself
- What does
useContextreturn when there's no provider above the component? - Why put state and dispatch in separate contexts?
- When is composition a better fix for prop drilling than context?
Completion is saved in this browser only. It does not measure mastery.