[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"search-suggestions":44,"article-usedeferredvalue-react-search-lag":93,"path-membership-usedeferredvalue-react-search-lag":272,"related-usedeferredvalue-react-search-lag":273,"code:jsx:true:c868rp":398,"code:jsx:true:1c99il5":399,"comments-01a1c5e4-2058-7020-8330-e4bbfc5f5a5c":400},[4,20,32],{"id":5,"slug":6,"name":7,"tagline":8,"description":9,"accentFrom":10,"accentTo":11,"icon":12,"defaultLocale":13,"locales":14,"features":16,"position":19},"019fe637-3d33-714b-b57f-23e163ffca0c","dev","Web Development","Read it. Run it. Prove it.","A post a day on modern web development — most with an editable playground and a quiz that explains every answer. Free, no account needed.","violet-500","cyan-400","◇","en",[13,15],"fa",{"courses":17,"paths":17,"articles":17,"exams":18,"flashcards":18,"packages":17,"community":17,"certificates":17,"teams":17,"commerce":17},true,false,0,{"id":21,"slug":22,"name":23,"tagline":24,"description":25,"accentFrom":26,"accentTo":10,"icon":27,"defaultLocale":13,"locales":28,"features":30,"position":31},"019fe637-3dc2-754c-8657-0f175bfee7c6","lang","Languages","Learn a language the way you learn a codebase.","Grammar explained the way good documentation explains an API — one idea at a time, each with a quiz.","amber-400","⌘",[13,15,29],"es",{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":17,"packages":18,"community":17,"certificates":17,"teams":18,"commerce":18},2,{"id":33,"slug":34,"name":35,"tagline":36,"description":37,"accentFrom":38,"accentTo":39,"icon":40,"defaultLocale":13,"locales":41,"features":42,"position":43},"7b3c16f2-931d-410e-802e-e1fa4edab7de","soft","Soft Skills","The half of the job nobody wrote documentation for.","Weekly, on the parts of working life that decide more than your code does — first weeks, meetings, interviews, promotions, and the people around you. Written from what actually happens, and recorded as a podcast you can listen to on the walk.","emerald-400","teal-300","◉",[13],{"courses":18,"paths":18,"articles":17,"exams":18,"flashcards":18,"packages":18,"community":17,"certificates":18,"teams":18,"commerce":18},3,[45,49,53,57,61,65,69,73,77,81,85,89],{"slug":46,"name":47,"articles":48},"webdev","Webdev",195,{"slug":50,"name":51,"articles":52},"javascript","Javascript",156,{"slug":54,"name":55,"articles":56},"frontend","Frontend",103,{"slug":58,"name":59,"articles":60},"tutorial","Tutorial",85,{"slug":62,"name":63,"articles":64},"css","Css",56,{"slug":66,"name":67,"articles":68},"typescript","Typescript",36,{"slug":70,"name":71,"articles":72},"performance","Performance",33,{"slug":74,"name":75,"articles":76},"programming","Programming",26,{"slug":78,"name":79,"articles":80},"react","React",23,{"slug":82,"name":83,"articles":84},"node","Node",19,{"slug":86,"name":87,"articles":88},"browser","Browser",18,{"slug":90,"name":91,"articles":92},"nextjs","Nextjs",13,{"id":94,"slug":95,"title":96,"subtitle":97,"excerpt":98,"coverUrl":99,"locale":13,"readingMinutes":100,"publishedAt":101,"viewCount":102,"likeCount":19,"commentCount":19,"author":103,"vertical":108,"topic":109,"tags":110,"_count":115,"playground":117,"body":119,"bodyMd":255,"seo":256,"translationGroupId":259,"series":97,"podcastUrl":97,"verticalId":5,"thread":260,"assessments":262,"translations":268,"quiz":270},"01a1c5e4-2058-7020-8330-e4bbfc5f5a5c","usedeferredvalue-react-search-lag","You're debouncing search input. `useDeferredValue` skips the timer.",null,"A client-side filter over 10,000 rows doesn't need a server, so there's no network call to debounce — but the keystroke still stutters. useDeferredValue fixes the actual cause: a slow render, not a slow request.","\u002Fmedia\u002Fcovers\u002Fusedeferredvalue-react-search-lag.png",6,"2026-11-27T11:41:22.834Z",16,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[111,112,113,114],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":70,"name":71,"color":97},{"slug":46,"name":47,"color":97},{"assessments":116},1,{"slug":95,"title":118},"useDeferredValue — interactive playground",{"blocks":120,"version":116},[121,125,128,132,135,141,144,147,150,154,157,161,164,167,170,173,176,179,182,185,188,191,194,197,200,203,206,209,212,215,218,221,224,227,230,237,240,243,246,249],{"id":122,"html":123,"type":124},"b1","\u003Cp>Type \u003Ccode>react\u003C\u002Fcode> into a search box filtering 10,000 rows, and watch the input lag half a beat behind your own keystrokes. Open React DevTools and the component isn&#39;t broken — it&#39;s doing exactly what you told it to. It&#39;s just doing all of it, every time, before it lets the next character land.\u003C\u002Fp>","paragraph",{"id":126,"html":127,"type":124},"b2","\u003Cp>The fix half the internet reaches for is a debounce. Wait 300ms after the user stops typing, then filter. It feels like it should work — fewer renders, less work. Try it in a real app and the stutter doesn&#39;t go away. It just moves to the end: the box stays suspiciously quiet for 300ms, then the final keystroke drags along a full re-filter of 10,000 rows, and \u003Cem>that\u003C\u002Fem> frame is the one that hitches.\u003C\u002Fp>",{"id":129,"html":130,"text":130,"type":131,"level":31},"b3","Debounce was never fixing the slow part","heading",{"id":133,"html":134,"type":124},"b4","\u003Cp>Here&#39;s the part that&#39;s easy to miss: debounce doesn&#39;t make a render cheaper. It only makes it less frequent.\u003C\u002Fp>",{"id":136,"code":137,"type":138,"language":139,"highlight":140},"b5","function Search({ items }) {\n  const [query, setQuery] = useState(\"\");\n  const [debounced, setDebounced] = useState(\"\");\n\n  useEffect(() => {\n    const id = setTimeout(() => setDebounced(query), 300);\n    return () => clearTimeout(id);\n  }, [query]);\n\n  \u002F\u002F still a synchronous, blocking filter — just a rarer one, thanks to\n  \u002F\u002F useMemo skipping it on the renders where `debounced` hasn't changed\n  const results = useMemo(\n    () => items.filter((i) => i.name.includes(debounced)),\n    [items, debounced]\n  );\n\n  return (\n    \u003C>\n      \u003Cinput value={query} onChange={(e) => setQuery(e.target.value)} \u002F>\n      \u003CList items={results} \u002F>\n    \u003C\u002F>\n  );\n}","code","jsx",[],{"id":142,"html":143,"type":124},"b6","\u003Cp>\u003Ccode>debounced\u003C\u002Fcode> changes less often than \u003Ccode>query\u003C\u002Fcode> — that part works. But when it \u003Cem>does\u003C\u002Fem> change, filtering 10,000 rows and re-rendering however many of them matched still happens on the main thread, still blocking, in one synchronous commit. You&#39;ve traded &quot;stutters on every keystroke&quot; for &quot;freezes for one frame, 300ms after you stop.&quot; Neither one is &quot;the input never lags&quot; — and the freeze gets worse the more rows there are to render, not just the more rows there are to filter.\u003C\u002Fp>",{"id":145,"html":146,"type":124},"b7","\u003Cp>And there&#39;s a second cost nobody budgets for: that \u003Ccode>setTimeout\u003C\u002Fcode> is tracking state that has nothing to do with the server. If \u003Ccode>items\u003C\u002Fcode> is already in memory — no fetch, no endpoint, nothing to rate-limit — you&#39;ve added a timer, a cleanup function, and a second piece of state to solve a problem debounce was never built for. Debounce exists to cut down \u003Cem>how often\u003C\u002Fem> a side effect fires. A local array filter isn&#39;t a side effect. It&#39;s a render.\u003C\u002Fp>",{"id":148,"html":149,"type":124},"b8","\u003Cp>Before you scroll — what&#39;s actually slow here: the filtering, or the fact that it runs on every keystroke?\u003C\u002Fp>",{"id":151,"html":152,"text":153,"type":131,"level":31},"b9","The fix that doesn&#39;t ask you to pick a delay","The fix that doesn't ask you to pick a delay",{"id":155,"html":156,"type":124},"b10","\u003Cp>\u003Ccode>useDeferredValue\u003C\u002Fcode> is a React hook built for exactly this split: let the input update immediately, every time, and let the \u003Cem>expensive\u003C\u002Fem> thing that depends on it lag behind on purpose.\u003C\u002Fp>",{"id":158,"code":159,"type":138,"language":139,"highlight":160},"b11","import { useState, useDeferredValue, memo } from \"react\";\n\nfunction Search({ items }) {\n  const [query, setQuery] = useState(\"\");\n  const deferredQuery = useDeferredValue(query);\n  const isStale = query !== deferredQuery;\n\n  return (\n    \u003C>\n      \u003Cinput value={query} onChange={(e) => setQuery(e.target.value)} \u002F>\n      \u003Cdiv style={{ opacity: isStale ? 0.6 : 1 }}>\n        \u003CList items={items} query={deferredQuery} \u002F>\n      \u003C\u002Fdiv>\n    \u003C\u002F>\n  );\n}\n\n\u002F\u002F The filter has to live INSIDE the memoized component, keyed off the\n\u002F\u002F deferred value — that's what gives memo something stable to bail out on.\n\u002F\u002F Filtering in Search instead (and just handing List the result) would run\n\u002F\u002F the expensive work on every keystroke regardless of what's deferred.\nconst List = memo(function List({ items, query }) {\n  const results = items.filter((i) => i.name.includes(query));\n  return \u003Cul>{results.map((i) => \u003Cli key={i.id}>{i.name}\u003C\u002Fli>)}\u003C\u002Ful>;\n});",[],{"id":162,"html":163,"type":124},"b12","\u003Cp>No \u003Ccode>setTimeout\u003C\u002Fcode>. No &quot;how many milliseconds feels right.&quot; \u003Ccode>query\u003C\u002Fcode> updates on every keystroke at full priority, so the input itself never lags — React treats typing as urgent and always renders it first. \u003Ccode>deferredQuery\u003C\u002Fcode> is a separate value that trails behind: React renders the list with the \u003Cem>old\u003C\u002Fem> deferred value first (cheap, since \u003Ccode>List\u003C\u002Fcode> is memoized and its props haven&#39;t changed), then — in the background, interruptible — renders it again with the new one.\u003C\u002Fp>",{"id":165,"html":166,"type":124},"b13","\u003Cp>That word, interruptible, is the actual mechanism, and it&#39;s the thing debounce can&#39;t do. If you type a second character before the deferred re-render finishes, React throws away that half-finished background work and starts over with the latest value, instead of finishing a now-stale render first. A debounce timer can&#39;t abandon work mid-flight like that — it can only decide when to start it.\u003C\u002Fp>",{"id":168,"html":169,"type":124},"b14","\u003Cp>Open your profiler and try both versions on a list of a few thousand rows. The debounced one shows long blocking tasks lined up end to end. The deferred one shows the same total filtering work, but broken into renders that each yield back to the browser — the keystroke you just made always wins the next frame.\u003C\u002Fp>",{"id":171,"html":172,"text":172,"type":131,"level":31},"b15","Where it stops helping",{"id":174,"html":175,"type":124},"b16","\u003Cp>\u003Ccode>useDeferredValue\u003C\u002Fcode> doesn&#39;t make filtering or rendering 10,000 rows faster. If that work takes 40ms, it still takes 40ms somewhere — the hook controls \u003Cem>when\u003C\u002Fem> React is allowed to start and finish that render relative to the next keystroke, and lets it move on to a newer update instead of committing a result that&#39;s already stale. If your list still needs virtualization or a better filtering algorithm, you still need to do that work; this just stops an already-reasonable render from fighting the keyboard for priority.\u003C\u002Fp>",{"id":177,"html":178,"type":124},"b17","\u003Cp>And it isn&#39;t a debounce replacement for the case debounce actually exists for: rate-limiting a \u003Cem>request\u003C\u002Fem>. If \u003Ccode>query\u003C\u002Fcode> drives a \u003Ccode>fetch\u003C\u002Fcode> to a search endpoint, you still want to wait before firing it — nobody wants an API call per keystroke, and \u003Ccode>useDeferredValue\u003C\u002Fcode> won&#39;t cut that count down, because it&#39;s a rendering primitive, not a networking one. Keep debouncing the request. Stop debouncing the render.\u003C\u002Fp>",{"id":180,"html":181,"type":124},"b18","\u003Cp>The \u003Ccode>isStale\u003C\u002Fcode> flag is worth keeping even once the lag is gone — not for performance, but for honesty with the reader: a slightly dimmed list for the few milliseconds between &quot;you typed&quot; and &quot;the filtered results landed&quot; tells them the app noticed their keystroke, instead of silently pretending nothing happened.\u003C\u002Fp>",{"id":183,"html":184,"type":124},"b19","\u003Cp>Next time a search box or a filter panel stutters, check which one you actually have: a request worth delaying, or a render that was never doing it concurrently in the first place.\u003C\u002Fp>",{"id":186,"html":187,"type":124},"b20","\u003C!-- playground:start -->",{"id":189,"html":190,"text":190,"type":131,"level":31},"b21","🎮 Try it yourself",{"id":192,"html":193,"type":124},"b22","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusedeferredvalue-react-search-lag\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":195,"html":196,"type":124},"b23","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":198,"html":199,"type":124},"b24","\u003C!-- playground:end -->",{"id":201,"html":202,"text":202,"type":131,"level":31},"b25","The part worth keeping",{"id":204,"html":205,"type":124},"b26","\u003Cp>Debounce answers &quot;how often.&quot; \u003Ccode>useDeferredValue\u003C\u002Fcode> answers &quot;what&#39;s allowed to interrupt what.&quot; They look like the same fix because they both make a laggy search box feel better — but only one of them is actually about rendering, and a search box filtering data you already have is a rendering problem first.\u003C\u002Fp>",{"id":207,"html":208,"type":124},"b27","\u003Cp>Which search box in your own codebase has a debounce timer guarding a filter that never touches the network? That&#39;s the one worth checking first.\u003C\u002Fp>",{"id":210,"html":211,"type":124},"b28","\u003C!-- quiz:start -->",{"id":213,"html":214,"text":214,"type":131,"level":31},"b29","🧠 Test yourself",{"id":216,"html":217,"type":124},"b30","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusedeferredvalue-react-search-lag\u002Fquiz\">Take the 7-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":219,"html":220,"type":124},"b31","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":222,"html":223,"type":124},"b32","\u003C!-- quiz:end -->",{"id":225,"html":226,"type":124},"b33","\u003C!-- related:start -->",{"id":228,"html":229,"text":229,"type":131,"level":31},"b34","📚 Read next",{"id":231,"type":232,"items":233,"ordered":18},"b35","list",[234,235,236],"\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finput-lag-bug-debounce-cant-fix\">Your Search Box Lags. Debounce Hides It; \u003Ccode>useTransition\u003C\u002Fcode> Fixes It\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ffindlast-search-from-end\">You copy and reverse the array to find the last match. \u003Ccode>findLast()\u003C\u002Fcode> searches from the end directly.\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-style-queries-react-to-custom-properties\">Container queries can check more than size — style queries let components read custom property values\u003C\u002Fa>",{"id":238,"html":239,"type":124},"b36","\u003C!-- related:end -->",{"id":241,"type":242},"b37","divider",{"id":244,"html":245,"type":124},"b38","\u003Cp>🚀 \u003Cstrong>Want more like this?\u003C\u002Fstrong> Every guide, playground, and quiz lives on \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">bestpractic.org\u003C\u002Fa>\u003C\u002Fstrong> — open it and \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002F\">sign up free\u003C\u002Fa>\u003C\u002Fstrong> so the next one finds you.\u003C\u002Fp>",{"id":247,"html":248,"type":124},"b39","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":250,"type":232,"items":251,"ordered":18},"b40",[252,253,254],"⭐ \u003Cstrong>GitHub\u003C\u002Fstrong> — follow me and star the projects: \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Fparsajiravand\">github.com\u002Fparsajiravand\u003C\u002Fa>","💬 \u003Cstrong>Discord\u003C\u002Fstrong> — join the frontend best-practices community: \u003Ca href=\"https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ\">discord.gg\u002Fd9KRhuAwQ\u003C\u002Fa>","📸 \u003Cstrong>Instagram\u003C\u002Fstrong> — frontend best practices, daily: \u003Ca href=\"https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F\">@bestpractice___\u003C\u002Fa>","Type `react` into a search box filtering 10,000 rows, and watch the input lag half a beat behind your own keystrokes. Open React DevTools and the component isn't broken — it's doing exactly what you told it to. It's just doing all of it, every time, before it lets the next character land.\n\nThe fix half the internet reaches for is a debounce. Wait 300ms after the user stops typing, then filter. It feels like it should work — fewer renders, less work. Try it in a real app and the stutter doesn't go away. It just moves to the end: the box stays suspiciously quiet for 300ms, then the final keystroke drags along a full re-filter of 10,000 rows, and *that* frame is the one that hitches.\n\n## Debounce was never fixing the slow part\n\nHere's the part that's easy to miss: debounce doesn't make a render cheaper. It only makes it less frequent.\n\n```jsx\nfunction Search({ items }) {\n  const [query, setQuery] = useState(\"\");\n  const [debounced, setDebounced] = useState(\"\");\n\n  useEffect(() => {\n    const id = setTimeout(() => setDebounced(query), 300);\n    return () => clearTimeout(id);\n  }, [query]);\n\n  \u002F\u002F still a synchronous, blocking filter — just a rarer one, thanks to\n  \u002F\u002F useMemo skipping it on the renders where `debounced` hasn't changed\n  const results = useMemo(\n    () => items.filter((i) => i.name.includes(debounced)),\n    [items, debounced]\n  );\n\n  return (\n    \u003C>\n      \u003Cinput value={query} onChange={(e) => setQuery(e.target.value)} \u002F>\n      \u003CList items={results} \u002F>\n    \u003C\u002F>\n  );\n}\n```\n\n`debounced` changes less often than `query` — that part works. But when it *does* change, filtering 10,000 rows and re-rendering however many of them matched still happens on the main thread, still blocking, in one synchronous commit. You've traded \"stutters on every keystroke\" for \"freezes for one frame, 300ms after you stop.\" Neither one is \"the input never lags\" — and the freeze gets worse the more rows there are to render, not just the more rows there are to filter.\n\nAnd there's a second cost nobody budgets for: that `setTimeout` is tracking state that has nothing to do with the server. If `items` is already in memory — no fetch, no endpoint, nothing to rate-limit — you've added a timer, a cleanup function, and a second piece of state to solve a problem debounce was never built for. Debounce exists to cut down *how often* a side effect fires. A local array filter isn't a side effect. It's a render.\n\nBefore you scroll — what's actually slow here: the filtering, or the fact that it runs on every keystroke?\n\n## The fix that doesn't ask you to pick a delay\n\n`useDeferredValue` is a React hook built for exactly this split: let the input update immediately, every time, and let the *expensive* thing that depends on it lag behind on purpose.\n\n```jsx\nimport { useState, useDeferredValue, memo } from \"react\";\n\nfunction Search({ items }) {\n  const [query, setQuery] = useState(\"\");\n  const deferredQuery = useDeferredValue(query);\n  const isStale = query !== deferredQuery;\n\n  return (\n    \u003C>\n      \u003Cinput value={query} onChange={(e) => setQuery(e.target.value)} \u002F>\n      \u003Cdiv style={{ opacity: isStale ? 0.6 : 1 }}>\n        \u003CList items={items} query={deferredQuery} \u002F>\n      \u003C\u002Fdiv>\n    \u003C\u002F>\n  );\n}\n\n\u002F\u002F The filter has to live INSIDE the memoized component, keyed off the\n\u002F\u002F deferred value — that's what gives memo something stable to bail out on.\n\u002F\u002F Filtering in Search instead (and just handing List the result) would run\n\u002F\u002F the expensive work on every keystroke regardless of what's deferred.\nconst List = memo(function List({ items, query }) {\n  const results = items.filter((i) => i.name.includes(query));\n  return \u003Cul>{results.map((i) => \u003Cli key={i.id}>{i.name}\u003C\u002Fli>)}\u003C\u002Ful>;\n});\n```\n\nNo `setTimeout`. No \"how many milliseconds feels right.\" `query` updates on every keystroke at full priority, so the input itself never lags — React treats typing as urgent and always renders it first. `deferredQuery` is a separate value that trails behind: React renders the list with the *old* deferred value first (cheap, since `List` is memoized and its props haven't changed), then — in the background, interruptible — renders it again with the new one.\n\nThat word, interruptible, is the actual mechanism, and it's the thing debounce can't do. If you type a second character before the deferred re-render finishes, React throws away that half-finished background work and starts over with the latest value, instead of finishing a now-stale render first. A debounce timer can't abandon work mid-flight like that — it can only decide when to start it.\n\nOpen your profiler and try both versions on a list of a few thousand rows. The debounced one shows long blocking tasks lined up end to end. The deferred one shows the same total filtering work, but broken into renders that each yield back to the browser — the keystroke you just made always wins the next frame.\n\n## Where it stops helping\n\n`useDeferredValue` doesn't make filtering or rendering 10,000 rows faster. If that work takes 40ms, it still takes 40ms somewhere — the hook controls *when* React is allowed to start and finish that render relative to the next keystroke, and lets it move on to a newer update instead of committing a result that's already stale. If your list still needs virtualization or a better filtering algorithm, you still need to do that work; this just stops an already-reasonable render from fighting the keyboard for priority.\n\nAnd it isn't a debounce replacement for the case debounce actually exists for: rate-limiting a *request*. If `query` drives a `fetch` to a search endpoint, you still want to wait before firing it — nobody wants an API call per keystroke, and `useDeferredValue` won't cut that count down, because it's a rendering primitive, not a networking one. Keep debouncing the request. Stop debouncing the render.\n\nThe `isStale` flag is worth keeping even once the lag is gone — not for performance, but for honesty with the reader: a slightly dimmed list for the few milliseconds between \"you typed\" and \"the filtered results landed\" tells them the app noticed their keystroke, instead of silently pretending nothing happened.\n\nNext time a search box or a filter panel stutters, check which one you actually have: a request worth delaying, or a render that was never doing it concurrently in the first place.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusedeferredvalue-react-search-lag\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## The part worth keeping\n\nDebounce answers \"how often.\" `useDeferredValue` answers \"what's allowed to interrupt what.\" They look like the same fix because they both make a laggy search box feel better — but only one of them is actually about rendering, and a search box filtering data you already have is a rendering problem first.\n\nWhich search box in your own codebase has a debounce timer guarding a filter that never touches the network? That's the one worth checking first.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 7-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusedeferredvalue-react-search-lag\u002Fquiz)**\n\n_Instant feedback, a hint on every question, and an explanation for each answer — right or wrong._\n\n\u003C!-- quiz:end -->\n\n\u003C!-- related:start -->\n\n## 📚 Read next\n\n- [Your Search Box Lags. Debounce Hides It; `useTransition` Fixes It](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Finput-lag-bug-debounce-cant-fix)\n- [You copy and reverse the array to find the last match. `findLast()` searches from the end directly.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ffindlast-search-from-end)\n- [Container queries can check more than size — style queries let components read custom property values](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fcss-style-queries-react-to-custom-properties)\n\n\u003C!-- related:end -->\n\n---\n\n🚀 **Want more like this?** Every guide, playground, and quiz lives on **[bestpractic.org](https:\u002F\u002Fbestpractic.org\u002F)** — open it and **[sign up free](https:\u002F\u002Fbestpractic.org\u002F)** so the next one finds you.\n\n*Thanks for reading! Let's stay connected:*\n\n- ⭐ **GitHub** — follow me and star the projects: [github.com\u002Fparsajiravand](https:\u002F\u002Fgithub.com\u002Fparsajiravand)\n- 💬 **Discord** — join the frontend best-practices community: [discord.gg\u002Fd9KRhuAwQ](https:\u002F\u002Fdiscord.gg\u002Fd9KRhuAwQ)\n- 📸 **Instagram** — frontend best practices, daily: [@bestpractice___](https:\u002F\u002Fwww.instagram.com\u002Fbestpractice___\u002F)",{"title":96,"canonical":257,"description":258},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusedeferredvalue-react-search-lag","A client-side filter over 10,000 rows doesn't need a server, so there's no network call to debounce — but the keystroke still stutters. useDeferredValue fixes the actual cause: a s","01a1c5e4-2058-7020-8330-e83edd17bb2a",{"id":261,"locked":18},"01a1c5e4-2081-71b8-9eb6-f53df2d0ecb1",[263],{"id":264,"slug":95,"title":265,"_count":266},"01a1c5e4-20a1-756b-ac45-50068d68ed74","useDeferredValue: keeping typing smooth",{"questions":267},7,[269],{"locale":13,"slug":95},{"id":264,"slug":95,"title":265,"_count":271,"questionCount":267},{"questions":267},[],{"items":274,"meta":396},[275,293,311,322,340,359,378],{"id":276,"slug":277,"title":278,"subtitle":97,"excerpt":279,"coverUrl":280,"locale":13,"readingMinutes":100,"publishedAt":281,"viewCount":282,"likeCount":19,"commentCount":19,"author":283,"vertical":284,"topic":285,"tags":286,"_count":291,"playground":292,"hasQuiz":17,"hasPlayground":17},"01a1fce0-de91-712e-bc98-72dba2b10bf5","react-use-api-promises-context","`use()` Breaks the Rules of Hooks on Purpose. Here's the Catch.","React's `use()` reads a promise or context mid-render and skips the Rules of Hooks on purpose — but that same freedom hides a caching trap that resuspends your component forever if you miss it.","\u002Fmedia\u002Fcovers\u002Freact-use-api-promises-context.png","2026-11-27T11:49:31.813Z",30,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[287,288,289,290],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":46,"name":47,"color":97},{"slug":54,"name":55,"color":97},{"assessments":116},{"slug":277},{"id":294,"slug":295,"title":296,"subtitle":97,"excerpt":297,"coverUrl":298,"locale":13,"readingMinutes":92,"publishedAt":299,"viewCount":300,"likeCount":19,"commentCount":19,"author":301,"vertical":302,"topic":303,"tags":304,"_count":309,"playground":310,"hasQuiz":17,"hasPlayground":17},"01a1df1b-203c-7390-aa4a-3c6b678e7abe","nextjs-weekly-error-retry-vs-reset","Next.js 16.3 error.js: retry vs reset Aren't Interchangeable","Next.js 16.3 stabilized error.js's retry(), which re-fetches on recovery — reset() only clears state. The real difference, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fnextjs-weekly-error-retry-vs-reset.png","2026-11-27T11:42:24.474Z",14,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":90,"name":91},[305,306,307,308],{"slug":90,"name":91,"color":97},{"slug":78,"name":79,"color":97},{"slug":46,"name":47,"color":97},{"slug":58,"name":59,"color":97},{"assessments":116},{"slug":295},{"id":94,"slug":95,"title":96,"subtitle":97,"excerpt":98,"coverUrl":99,"locale":13,"readingMinutes":100,"publishedAt":101,"viewCount":88,"likeCount":19,"commentCount":19,"author":312,"vertical":313,"topic":314,"tags":315,"_count":320,"playground":321,"hasQuiz":17,"hasPlayground":17},{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[316,317,318,319],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":70,"name":71,"color":97},{"slug":46,"name":47,"color":97},{"assessments":116},{"slug":95},{"id":323,"slug":324,"title":325,"subtitle":97,"excerpt":326,"coverUrl":327,"locale":13,"readingMinutes":300,"publishedAt":328,"viewCount":329,"likeCount":19,"commentCount":19,"author":330,"vertical":331,"topic":332,"tags":333,"_count":338,"playground":339,"hasQuiz":17,"hasPlayground":17},"01a1623b-51e7-7669-89ad-eb54d67696eb","react-weekly-activity-component","React Activity Component: The State Between Render and Remount","React's Activity component hides a subtree without unmounting it — what state, effects, and renders actually do, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-activity-component.png","2026-11-02T06:10:18.569Z",425,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[334,335,336,337],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":58,"name":59,"color":97},{"slug":46,"name":47,"color":97},{"assessments":116},{"slug":324},{"id":341,"slug":342,"title":343,"subtitle":97,"excerpt":344,"coverUrl":345,"locale":13,"readingMinutes":346,"publishedAt":347,"viewCount":348,"likeCount":19,"commentCount":19,"author":349,"vertical":350,"topic":351,"tags":352,"_count":357,"playground":358,"hasQuiz":17,"hasPlayground":17},"01a14e81-eaa5-700a-a6f6-3be4ffe47c2b","usesyncexternalstore-tearing-fix","Your Custom Hooks Tear in React 18. `useSyncExternalStore` Fixes It.","A useState + useEffect hook that subscribes to window size, localStorage, or a WebSocket looks fine until React 18's concurrent rendering shows two parts of your UI two different values at once. useSyncExternalStore is the hook built to stop that.","\u002Fmedia\u002Fcovers\u002Fusesyncexternalstore-tearing-fix.png",5,"2026-10-23T06:11:03.306Z",458,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[353,354,355,356],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":46,"name":47,"color":97},{"slug":54,"name":55,"color":97},{"assessments":116},{"slug":342},{"id":360,"slug":361,"title":362,"subtitle":97,"excerpt":363,"coverUrl":364,"locale":13,"readingMinutes":365,"publishedAt":366,"viewCount":367,"likeCount":19,"commentCount":19,"author":368,"vertical":369,"topic":370,"tags":371,"_count":376,"playground":377,"hasQuiz":17,"hasPlayground":17},"01a13e2e-d5ae-707f-a6c5-726f2ed01ab0","react-weekly-useeffectevent-stale-closures","React 19.2 useEffectEvent: Why It Won't Fix Your Deps Array","React's useEffectEvent (stable in 19.2) kills stale closures in Effects without a ref trick — but it's not a deps-array shortcut. Guide + cheat sheet.","\u002Fmedia\u002Fcovers\u002Freact-weekly-useeffectevent-stale-closures.png",15,"2026-10-17T12:20:57.469Z",434,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":78,"name":79},[372,373,374,375],{"slug":78,"name":79,"color":97},{"slug":50,"name":51,"color":97},{"slug":58,"name":59,"color":97},{"slug":46,"name":47,"color":97},{"assessments":116},{"slug":361},{"id":379,"slug":380,"title":381,"subtitle":97,"excerpt":382,"coverUrl":383,"locale":13,"readingMinutes":365,"publishedAt":384,"viewCount":385,"likeCount":19,"commentCount":19,"author":386,"vertical":387,"topic":388,"tags":389,"_count":394,"playground":395,"hasQuiz":17,"hasPlayground":17},"01a120b9-d611-74ef-ad15-a267677c3251","nextjs-weekly-image-priority-quality-changes","Next.js 16 Image: priority Deprecated, quality Now Allowlisted","Next.js 16 quietly deprecated Image's priority for preload and restricts quality to an allowlist (default: 75). What breaks, plus a copy-paste cheat sheet.","\u002Fmedia\u002Fcovers\u002Fnextjs-weekly-image-priority-quality-changes.png","2026-10-13T06:10:29.815Z",852,{"id":104,"name":105,"username":106,"avatarUrl":97,"headline":107},{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":90,"name":91},[390,391,392,393],{"slug":90,"name":91,"color":97},{"slug":78,"name":79,"color":97},{"slug":46,"name":47,"color":97},{"slug":58,"name":59,"color":97},{"assessments":116},{"slug":380},{"page":116,"perPage":267,"total":80,"totalPages":397},4,"\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003Cdiv>18\u003C\u002Fdiv>\u003Cdiv>19\u003C\u002Fdiv>\u003Cdiv>20\u003C\u002Fdiv>\u003Cdiv>21\u003C\u002Fdiv>\u003Cdiv>22\u003C\u002Fdiv>\u003Cdiv>23\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Search\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> items \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>query\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> setQuery\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useState\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>debounced\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> setDebounced\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useState\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-func\">useEffect\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n    \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> id \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setTimeout\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setDebounced\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>query\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-num\">300\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n    \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">clearTimeout\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>id\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>query\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-cmnt\">\u002F\u002F still a synchronous, blocking filter — just a rarer one, thanks to\n\u003C\u002Fspan>  \u003Cspan class=\"shj-cmnt\">\u002F\u002F useMemo skipping it on the renders where `debounced` hasn't changed\n\u003C\u002Fspan>  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> results \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useMemo\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\n    \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> items\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">filter\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>i\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> i\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>name\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">includes\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>debounced\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan>\n    \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>items\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> debounced\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">input\u003C\u002Fspan> \u003Cspan class=\"shj-class\">value\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>query\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-class\">onChange\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setQuery\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>target\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>value\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">\u002F&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">List\u003C\u002Fspan> \u003Cspan class=\"shj-class\">items\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>results\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">\u002F&gt;\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>","\u003Cdiv class=\"shj shj-lang-jsx shj-multiline\" data-lang=\"jsx\">\u003Cdiv class=\"shj-scroll\">\u003Cdiv class=\"shj-numbers\">\u003Cdiv>1\u003C\u002Fdiv>\u003Cdiv>2\u003C\u002Fdiv>\u003Cdiv>3\u003C\u002Fdiv>\u003Cdiv>4\u003C\u002Fdiv>\u003Cdiv>5\u003C\u002Fdiv>\u003Cdiv>6\u003C\u002Fdiv>\u003Cdiv>7\u003C\u002Fdiv>\u003Cdiv>8\u003C\u002Fdiv>\u003Cdiv>9\u003C\u002Fdiv>\u003Cdiv>10\u003C\u002Fdiv>\u003Cdiv>11\u003C\u002Fdiv>\u003Cdiv>12\u003C\u002Fdiv>\u003Cdiv>13\u003C\u002Fdiv>\u003Cdiv>14\u003C\u002Fdiv>\u003Cdiv>15\u003C\u002Fdiv>\u003Cdiv>16\u003C\u002Fdiv>\u003Cdiv>17\u003C\u002Fdiv>\u003Cdiv>18\u003C\u002Fdiv>\u003Cdiv>19\u003C\u002Fdiv>\u003Cdiv>20\u003C\u002Fdiv>\u003Cdiv>21\u003C\u002Fdiv>\u003Cdiv>22\u003C\u002Fdiv>\u003Cdiv>23\u003C\u002Fdiv>\u003Cdiv>24\u003C\u002Fdiv>\u003Cdiv>25\u003C\u002Fdiv>\u003C\u002Fdiv>\u003Cdiv class=\"shj-code\">\u003Cspan class=\"shj-kwd\">import\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> useState\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> useDeferredValue\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> memo \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">from\u003C\u002Fspan> \u003Cspan class=\"shj-str\">\"react\"\u003C\u002Fspan>;\n\n\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">Search\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> items \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">[\u003C\u002Fspan>query\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> setQuery\u003Cspan class=\"shj-bracket\">]\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useState\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-str\">\"\"\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> deferredQuery \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">useDeferredValue\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>query\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> isStale \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> query \u003Cspan class=\"shj-oper\">!==\u003C\u002Fspan> deferredQuery;\n\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">input\u003C\u002Fspan> \u003Cspan class=\"shj-class\">value\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>query\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-class\">onChange\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-func\">setQuery\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>e\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>target\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>value\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">\u002F&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">div\u003C\u002Fspan> \u003Cspan class=\"shj-class\">style\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> opacity\u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> isStale \u003Cspan class=\"shj-oper\">?\u003C\u002Fspan> \u003Cspan class=\"shj-num\">0.6\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">:\u003C\u002Fspan> \u003Cspan class=\"shj-num\">1\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n        \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">List\u003C\u002Fspan> \u003Cspan class=\"shj-class\">items\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>items\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-class\">query\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>deferredQuery\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">\u002F&gt;\u003C\u002Fspan>\n      \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">div\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n    \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\n  \u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\n\n\u003Cspan class=\"shj-cmnt\">\u002F\u002F The filter has to live INSIDE the memoized component, keyed off the\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F deferred value — that's what gives memo something stable to bail out on.\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F Filtering in Search instead (and just handing List the result) would run\n\u003C\u002Fspan>\u003Cspan class=\"shj-cmnt\">\u002F\u002F the expensive work on every keystroke regardless of what's deferred.\n\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> \u003Cspan class=\"shj-class\">List\u003C\u002Fspan> \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> \u003Cspan class=\"shj-func\">memo\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-kwd\">function\u003C\u002Fspan> \u003Cspan class=\"shj-class\">List\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan> items\u003Cspan class=\"shj-oper\">,\u003C\u002Fspan> query \u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-bracket\">{\u003C\u002Fspan>\n  \u003Cspan class=\"shj-kwd\">const\u003C\u002Fspan> results \u003Cspan class=\"shj-oper\">=\u003C\u002Fspan> items\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">filter\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>i\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> i\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>name\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">includes\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>query\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\n  \u003Cspan class=\"shj-kwd\">return\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">ul\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>results\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>\u003Cspan class=\"shj-func\">map\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">(\u003C\u002Fspan>i\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan> \u003Cspan class=\"shj-kwd\">=&gt;\u003C\u002Fspan> \u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u003C\u002Fspan>\u003Cspan class=\"shj-var\">li\u003C\u002Fspan> \u003Cspan class=\"shj-class\">key\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">={\u003C\u002Fspan>i\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>id\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">{\u003C\u002Fspan>i\u003Cspan class=\"shj-oper\">.\u003C\u002Fspan>name\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">li\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">}\u003C\u002Fspan>\u003Cspan class=\"shj-var\">\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&lt;\u002F\u003C\u002Fspan>\u003Cspan class=\"shj-var\">ul\u003C\u002Fspan>\u003Cspan class=\"shj-oper\">&gt;\u003C\u002Fspan>;\n\u003Cspan class=\"shj-bracket\">}\u003C\u002Fspan>\u003Cspan class=\"shj-bracket\">)\u003C\u002Fspan>;\u003C\u002Fdiv>\u003C\u002Fdiv>\u003C\u002Fdiv>",{"locked":18,"total":19,"comments":401},[]]