Structuring State — Where It Lives and What Belongs In It — Concept Check
Questions on Structuring State — Where It Lives and What Belongs In It. Most React bugs are state in the wrong place or state that should not exist. Deciding both correctly removes whole categories of bug before they happen.
Questions in this quiz
7 questions on Structuring State — Where It Lives and What Belongs In It — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A React component stores both `count` and `items` in its state. `count` is the number of items. What should you do?
- ALift `count` to a higher component
- BRemove `count` from state and derive it from `items`
- CUse `useMemo` to cache `count`
- DKeep both `count` and `items` in state for efficiency
2.In a React application, two sibling components need to access the same state. Where should this state be placed?
- AIn the second sibling component
- BIn a global store like Redux
- CIn the first sibling component
- DIn their common parent component
3.A developer uses three separate boolean states: `isLoading`, `isError`, and `isSuccess`. What is a potential issue?
- AIt prevents stale state
- BIt simplifies state management
- CIt allows impossible state combinations
- DIt improves performance
4.When should you consider using URL search params instead of component state in a React app?
- AFor filters and pagination
- BFor temporary UI states
- CFor local component states
- DFor global application themes
5.A component stores a selected object in its state. What is a better approach?
- AUse context to manage the object
- BStore only the object's ID
- CStore the entire object for easy access
- DUse `useMemo` to cache the object
6.Why might lifting state too high in a React app be problematic?
- AIt causes unnecessary re-renders of intermediate components
- BIt ensures all components have access to state
- CIt reduces component complexity
- DIt centralizes state management
7.What is the best practice for managing complex shared state across multiple routes in a React app?
- AUse local component state
- BLift state to the top component
- CStore state in URL search params
- DUse a store like Zustand or Redux