Advanced React Interview QuestionsAdvancedComparison
React · Question 98
What are the 'use memo' and 'use no memo' directives in React Compiler?
Direct answer
'use memo' explicitly opts a function into compiler optimization in configurations where that matters, while 'use no memo' opts a function out and should usually be treated as a targeted escape hatch.
| Directive | Purpose | Typical use |
|---|---|---|
| "use memo" | Request compiler optimization for the function/module | Annotation or incremental adoption strategies |
| "use no memo" | Prevent compiler optimization | Temporary compatibility or debugging escape hatch |
compiler-directives.jsx
function LegacyGrid() {
"use no memo";
return <ThirdPartyGrid />;
}
function OptimizedPanel() {
"use memo";
return <ExpensivePanel />;
}