StrictMode, Purity and Concurrent Rendering — Concept Check
Questions on StrictMode, Purity and Concurrent Rendering. React assumes your components are pure and may render them more than once, or abandon a render entirely. StrictMode makes violations visible in development.
Questions in this quiz
8 questions on StrictMode, Purity and Concurrent Rendering — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer notices that their React component's render function is being called twice in development mode. What could be causing this?
- AStrictMode is enabled, which double-invokes components to expose impure renders.
- BThe component has a memory leak that causes repeated renders.
- CReact is misconfigured and requires a reinstall.
- DThe component is inherently impure and React is trying to correct it.
2.You have a component that sets a document title during render. What issue might this cause?
- AIt ensures the title is always up-to-date with the render.
- BIt causes side effects, violating purity and potentially leading to bugs.
- CIt has no effect because React ignores DOM changes during render.
- DIt optimizes performance by setting the title early.
3.A React component uses `Math.random()` in its render method. What problem might this introduce?
- AIt improves performance by generating unique keys for elements.
- BIt ensures each render is unique, preventing caching issues.
- CIt breaks double-render checks and server rendering due to inconsistent outputs.
- DIt has no impact as React handles randomness internally.
4.In a React app, a developer uses `useRef` to prevent an effect from running twice. Why might this be problematic?
- AIt improves performance by avoiding unnecessary effect executions.
- BIt ensures effects always run in the correct order.
- CIt suppresses symptoms without addressing the root cause of missing cleanup.
- DIt is the correct way to ensure effects run only once.
5.A component's render function sorts its props array directly. What issue does this present?
- AIt ensures the props are always sorted before use.
- BIt has no effect as React handles prop mutations internally.
- CMutating props directly during render violates purity, leading to potential bugs.
- DIt optimizes the component by sorting data early.
6.Why does React's StrictMode double-invoke reducers and useMemo in development?
- ATo improve performance by caching results.
- BTo expose impure logic that may not be evident in single invocations.
- CTo ensure all hooks are used correctly and in order.
- DTo guarantee that effects are always cleaned up properly.
7.A developer uses `useTransition` in a component. What benefit does this provide?
- AIt marks updates as interruptible, keeping the UI responsive during expensive operations.
- BIt speeds up rendering by parallelizing updates.
- CIt ensures all updates are applied in sequence without interruption.
- DIt prevents any component from rendering more than once.
8.A React component sets a variable outside its function during render. What could this lead to?
- AIt ensures the variable is always updated with the latest render.
- BIt has no effect as React isolates component renders.
- CIt introduces side effects, violating the purity contract and causing potential bugs.
- DIt optimizes state management by sharing state across renders.