This problem is paper-only - see explanation for the canonical React reasoning.
Premature memoization is one of the most common mistakes in React code reviews. The auto-grader validates the decision rules.
Given a function call shaped { computeCostMs, callsPerRender, isReferentialDep, sourceRowsLargerThan10k }, return one of:
"useMemo"if the value should be memoized (significant compute OR a referential dep, OR working over a large input)."useCallback"if it's a function passed as a prop AND the recipient is React.memo-wrapped (model:isReferentialDep === true)."none"otherwise.
Decision tree implemented by the grader:
- computeCostMs > 5 →
"useMemo". - sourceRowsLargerThan10k →
"useMemo". - isReferentialDep →
"useCallback". - Otherwise →
"none".
(If both #1 and #3 hold, useMemo wins - the value itself needs caching.)
For the auto-grader: implement memoizationAdvice(input).