Explain compiler optimization assumptions
Optimize updates without changing the interface
React Compiler is an optional build-time optimizer for React components and Hooks. It analyzes code to decide when work can be reused across renders. This can reduce repeated calculations and child rendering, but an application must remain correct without the optimization. JSX transformation converts markup-like syntax into JavaScript calls; bundling assembles modules; minification reduces code size. None of these operations alone establishes that React Compiler has optimized a component. The primary teaching target here is React 19 with the stable compiler family; exact packages and build integration must be selected and verified before execution.
export function selectTiles(tiles, query){ const needle=query.trim().toLowerCase(); return tiles.filter(tile=>tile.name.toLowerCase().includes(needle));}For the records Moss, Quartz and Rose quartz, a query of quartz returns the last two records in original order. An empty query returns all three in a new array. The function does not mutate input, and has no dependency on a clock, browser or external state. This is a normal JavaScript helper: calling it outside a component or Hook does not automatically create a compiler-managed cache.
Compare the manual and automatic approaches
import React,{memo,useMemo} from 'react';import {selectTiles} from './c41-l01-s03.mjs';const TileList=memo(function TileList({tiles}){ return <ul>{tiles.map(tile=><li key={tile.id}>{tile.name}</li>)}</ul>;});export default function ManualCatalogue({tiles,query}){ const matches=useMemo(()=>selectTiles(tiles,query),[tiles,query]); return <TileList tiles={matches}/>;}The manual component asks React to reuse a calculated array while its dependencies are unchanged and offers the child a memoization boundary. Neither is a semantic guarantee that React will never repeat work. If a parent recreates the input array unnecessarily, the dependency identity changes. Keep inputs immutable. The list should still be right regardless of how many times it renders.
import React from 'react';import {selectTiles} from './c41-l01-s03.mjs';function TileList({tiles}){ return <ul>{tiles.map(tile=><li key={tile.id}>{tile.name}</li>)}</ul>;}export default function AutoCatalogue({tiles,query}){ const matches=selectTiles(tiles,query); return <TileList tiles={matches}/>;}The candidate intentionally has the same visible behavior as the manual baseline. A compatible compiler may optimize the calculation and element reuse, but whether it does so must be established from the actual compiler build. It does not share a universal cache among independent component instances. Use measurement rather than assuming faster interactions. For an existing app retain manual memoization until behavior and performance have been checked; changes to identities can affect downstream dependencies. Practice: predict both lists for empty, mixed-case and missing queries, and identify what must remain true when optimizations are disabled.