Question presented to candidate:
"Our team spends a lot of review time arguing about useMemo and useCallback. Next.js 16 says the React Compiler is stable. How would you turn it on, and how would you decide, with evidence, whether it is worth keeping?"
What a strong answer should cover:
- The React Compiler is a build-time tool that memoizes components and hooks automatically, so values and JSX are only recomputed when their inputs change.
- Enable it with top-level
reactCompiler: true(stable since 16.0, not on by default) plusbabel-plugin-react-compiler; 16.3 addedexperimental.turbopackRustReactCompiler, a native Rust port that needs no Babel plugin. - Options:
compilationMode: 'annotation'with"use memo"to opt in gradually, and"use no memo"to opt a component out. - Evaluate with numbers: render counts (React DevTools Profiler), interaction timings, and build time, before and after; the compiler adds build cost.
- It only optimises code that follows the Rules of React; code that mutates props or reads refs during render is skipped, so the lint rules matter.
Clarifying questions expected:
- "Where are the slow interactions today?" β the compiler fixes re-render waste, not slow data or large bundles.
- "Do we have a lot of manual memoization or code that breaks the Rules of React?"
Code / implementation expected: Yes β the config, the install command, and a before/after render measurement.