[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"verticals":3,"quiz-react-use-api-promises-context":44,"search-suggestions":60,"quiz-article-react-use-api-promises-context":109,"path-membership-react-use-api-promises-context":298},[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,{"id":45,"slug":46,"kind":47,"title":48,"description":49,"config":50,"verticalId":5,"vertical":55,"course":52,"_count":56,"access":57,"attempts":59,"questionCount":51},"01a1fce0-dec7-70f4-b44b-fb9a2f9669be","react-use-api-promises-context","PRACTICE_QUIZ","Test yourself — React's use() API","Six questions on what use() actually does with promises and context, and the one caching rule that keeps it from resuspending forever.",{"questionCount":51,"timeLimitSec":52,"shuffleQuestions":18,"shuffleOptions":17,"negativeMarking":19,"passScorePct":53,"maxAttempts":52,"revealAnswers":54,"allowFlagging":18,"allowBacktracking":17},6,null,70,"AFTER_SUBMIT",{"slug":6,"name":7},{"questions":51},{"allowed":17,"reason":58},"FREE",[],[61,65,69,73,77,81,85,89,93,97,101,105],{"slug":62,"name":63,"articles":64},"webdev","Webdev",195,{"slug":66,"name":67,"articles":68},"javascript","Javascript",156,{"slug":70,"name":71,"articles":72},"frontend","Frontend",103,{"slug":74,"name":75,"articles":76},"tutorial","Tutorial",85,{"slug":78,"name":79,"articles":80},"css","Css",56,{"slug":82,"name":83,"articles":84},"typescript","Typescript",36,{"slug":86,"name":87,"articles":88},"performance","Performance",33,{"slug":90,"name":91,"articles":92},"programming","Programming",26,{"slug":94,"name":95,"articles":96},"react","React",23,{"slug":98,"name":99,"articles":100},"node","Node",19,{"slug":102,"name":103,"articles":104},"browser","Browser",18,{"slug":106,"name":107,"articles":108},"nextjs","Nextjs",13,{"id":110,"slug":46,"title":111,"subtitle":52,"excerpt":112,"coverUrl":113,"locale":13,"readingMinutes":51,"publishedAt":114,"viewCount":115,"likeCount":19,"commentCount":19,"author":116,"vertical":121,"topic":122,"tags":123,"_count":128,"playground":130,"body":132,"bodyMd":284,"seo":285,"translationGroupId":288,"series":52,"podcastUrl":52,"verticalId":5,"thread":289,"assessments":291,"translations":294,"quiz":296},"01a1fce0-de91-712e-bc98-72dba2b10bf5","`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",29,{"id":117,"name":118,"username":119,"avatarUrl":52,"headline":120},"019fe637-3c25-7088-9034-39c9f15dc3c8","Parsa Jiravand","parsa","Frontend engineer · building bestpractic",{"slug":6,"name":7,"accentFrom":10,"accentTo":11},{"slug":94,"name":95},[124,125,126,127],{"slug":94,"name":95,"color":52},{"slug":66,"name":67,"color":52},{"slug":62,"name":63,"color":52},{"slug":70,"name":71,"color":52},{"assessments":129},1,{"slug":46,"title":131},"use() promise identity — interactive playground",{"blocks":133,"version":129},[134,138,141,146,149,155,158,161,165,168,171,175,178,182,185,188,191,194,197,200,203,206,209,213,216,219,223,226,229,232,235,238,241,244,247,250,253,256,259,266,269,272,275,278],{"id":135,"html":136,"type":137},"b1","\u003Cp>You rip out a \u003Ccode>useEffect\u003C\u002Fcode>, a \u003Ccode>useState\u003C\u002Fcode>, and a cleanup flag, replace all three with one line of \u003Ccode>use()\u003C\u002Fcode>, and the component looks cleaner than it has in months. Then you refresh the page and the loading spinner never stops. Network tab: the same request, firing again, and again, every few milliseconds, forever.\u003C\u002Fp>","paragraph",{"id":139,"html":140,"type":137},"b2","\u003Cp>Nothing in the code is wrong, exactly. You just found the one rule \u003Ccode>use()\u003C\u002Fcode> actually enforces — by being the React API that&#39;s allowed to break every other rule.\u003C\u002Fp>",{"id":142,"html":143,"text":144,"type":145,"level":31},"b3","The dance \u003Ccode>use()\u003C\u002Fcode> was built to end","The dance use() was built to end","heading",{"id":147,"html":148,"type":137},"b4","\u003Cp>Before \u003Ccode>use()\u003C\u002Fcode>, reading an async value inside a component meant writing the same fifteen lines everywhere:\u003C\u002Fp>",{"id":150,"code":151,"type":152,"language":153,"highlight":154},"b5","function Profile({ userId }) {\n  const [user, setUser] = useState(null);\n  const [loading, setLoading] = useState(true);\n\n  useEffect(() => {\n    let cancelled = false;\n    setLoading(true);\n    fetchUser(userId).then((data) => {\n      if (!cancelled) {\n        setUser(data);\n        setLoading(false);\n      }\n    });\n    return () => { cancelled = true; };\n  }, [userId]);\n\n  if (loading) return \u003CSpinner \u002F>;\n  return \u003CUserCard user={user} \u002F>;\n}","code","jsx",[],{"id":156,"html":157,"type":137},"b6","\u003Cp>Two pieces of state tracking one value. A \u003Ccode>cancelled\u003C\u002Fcode> flag so a slow response for the \u003Cem>old\u003C\u002Fem> \u003Ccode>userId\u003C\u002Fcode> doesn&#39;t overwrite a faster one for the new \u003Ccode>userId\u003C\u002Fcode>. None of it is about showing a user card — it&#39;s all plumbing to make \u003Ccode>useEffect\u003C\u002Fcode> behave like something it was never built to be: a way to read an async value.\u003C\u002Fp>",{"id":159,"html":160,"type":137},"b7","\u003Cp>\u003Ccode>use()\u003C\u002Fcode> reads it directly. No \u003Ccode>useEffect\u003C\u002Fcode>, no \u003Ccode>useState\u003C\u002Fcode>, no race-condition flag:\u003C\u002Fp>",{"id":162,"code":163,"type":152,"language":153,"highlight":164},"b8","import { use, Suspense, useMemo } from \"react\";\n\nfunction Profile({ userPromise }) {\n  const user = use(userPromise);\n  return \u003CUserCard user={user} \u002F>;\n}\n\nfunction ProfilePage({ userId }) {\n  const userPromise = useMemo(() => fetchUser(userId), [userId]);\n  return (\n    \u003CSuspense fallback={\u003CSpinner \u002F>}>\n      \u003CProfile userPromise={userPromise} \u002F>\n    \u003C\u002FSuspense>\n  );\n}",[],{"id":166,"html":167,"type":137},"b9","\u003Cp>\u003Ccode>use(userPromise)\u003C\u002Fcode> either returns the resolved value or, if the promise is still pending, \u003Cem>suspends\u003C\u002Fem> — the same mechanism \u003Ccode>React.lazy\u003C\u002Fcode> uses. React walks up to the nearest \u003Ccode>&lt;Suspense&gt;\u003C\u002Fcode> and shows its fallback instead of rendering \u003Ccode>Profile\u003C\u002Fcode> with nothing. When the promise settles, React re-renders \u003Ccode>Profile\u003C\u002Fcode>, and \u003Ccode>use()\u003C\u002Fcode> just returns the value like it was there all along. One line replaced the whole dance, and the race-condition flag is gone because there&#39;s only one state to track: the promise.\u003C\u002Fp>",{"id":169,"html":170,"type":137},"b10","\u003Cp>Before you scroll — does anything in that second version look like it could go wrong? Sit with it for a second.\u003C\u002Fp>",{"id":172,"html":173,"text":174,"type":145,"level":31},"b11","I simplified it one line further. That&#39;s when it broke.","I simplified it one line further. That's when it broke.",{"id":176,"html":177,"type":137},"b12","\u003Cp>The \u003Ccode>useMemo\u003C\u002Fcode> felt like an extra step, so I cut it:\u003C\u002Fp>",{"id":179,"code":180,"type":152,"language":153,"highlight":181},"b13","\u002F\u002F 🚫 looks identical, isn't\nfunction Profile({ userId }) {\n  const user = use(fetchUser(userId));\n  return \u003CUserCard user={user} \u002F>;\n}",[],{"id":183,"html":184,"type":137},"b14","\u003Cp>This is the version that floods the network tab. Here&#39;s why: every time \u003Ccode>Profile\u003C\u002Fcode> renders, \u003Ccode>fetchUser(userId)\u003C\u002Fcode> runs again and hands \u003Ccode>use()\u003C\u002Fcode> a \u003Cem>brand-new\u003C\u002Fem> promise object — even if \u003Ccode>userId\u003C\u002Fcode> hasn&#39;t changed. React has no way to know that this new promise represents &quot;the same request, still loading.&quot; It only knows it was just handed a pending promise it&#39;s never seen before, so it suspends again. The fallback shows, the promise eventually resolves, \u003Ccode>Profile\u003C\u002Fcode> re-renders, and on \u003Cem>that\u003C\u002Fem> render it calls \u003Ccode>fetchUser(userId)\u003C\u002Fcode> one more time — producing yet another new, unseen, pending promise. The loop doesn&#39;t stop because nothing ever breaks the chain.\u003C\u002Fp>",{"id":186,"html":187,"type":137},"b15","\u003Cp>\u003Ccode>useMemo\u003C\u002Fcode> was never decoration. It was the one thing making the promise&#39;s \u003Cem>identity\u003C\u002Fem> stable across renders — the same promise object came back out every time, as long as \u003Ccode>userId\u003C\u002Fcode> stayed the same — so React could recognize &quot;I&#39;ve already seen this one, it&#39;s done, here&#39;s the value&quot; instead of &quot;new pending work, suspend again.&quot;\u003C\u002Fp>",{"id":189,"html":190,"type":137},"b16","\u003Cp>That&#39;s the actual rule \u003Ccode>use()\u003C\u002Fcode> enforces, and it&#39;s stricter than anything \u003Ccode>useEffect\u003C\u002Fcode> ever asked of you: \u003Cstrong>the promise has to come from somewhere that caches it.\u003C\u002Fstrong> That&#39;s usually one of three places — a parent component that memoizes it (like the \u003Ccode>useMemo\u003C\u002Fcode> above), a Server Component, where the promise can be created fresh each request because the request itself is the cache boundary, or a Suspense-integrated data library (React Query, SWR, Relay) that&#39;s already solving this for you. Creating a fresh promise inside the same component that calls \u003Ccode>use()\u003C\u002Fcode> on it, every render, is the one pattern that&#39;s never safe.\u003C\u002Fp>",{"id":192,"html":193,"type":137},"b17","\u003Cp>One thing worth knowing before you lean on the \u003Ccode>useMemo\u003C\u002Fcode> version in production: React&#39;s own docs skip \u003Ccode>useMemo\u003C\u002Fcode> for this and reach straight for a persistent cache (a module-level \u003Ccode>Map\u003C\u002Fcode> keyed by the request, so the same promise comes back no matter what re-renders) — because \u003Ccode>useMemo\u003C\u002Fcode> is documented as a performance optimization, not a guaranteed one. It works in the \u003Ccode>ProfilePage\u003C\u002Fcode>\u002F\u003Ccode>Profile\u003C\u002Fcode> split above specifically because the memo lives in the \u003Cem>parent\u003C\u002Fem>, and the parent never suspends. Move that same \u003Ccode>useMemo\u003C\u002Fcode> down into the component that calls \u003Ccode>use()\u003C\u002Fcode>, and the first suspend throws the memoized value away with it — recreating the exact loop you were trying to fix.\u003C\u002Fp>",{"id":195,"html":196,"type":137},"b18","\u003C!-- playground:start -->",{"id":198,"html":199,"text":199,"type":145,"level":31},"b19","🎮 Try it yourself",{"id":201,"html":202,"type":137},"b20","\u003Cp>\u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-use-api-promises-context\u002Fplayground\">▶️ Open the interactive playground →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":204,"html":205,"type":137},"b21","\u003Cp>\u003Cem>Runs right in your browser — poke at it and watch the concept react live.\u003C\u002Fem>\u003C\u002Fp>",{"id":207,"html":208,"type":137},"b22","\u003C!-- playground:end -->",{"id":210,"html":211,"text":212,"type":145,"level":31},"b23","Why it&#39;s an API, not a hook","Why it's an API, not a hook",{"id":214,"html":215,"type":137},"b24","\u003Cp>Here&#39;s the part that&#39;s easy to miss if you only skim the React docs: \u003Ccode>use()\u003C\u002Fcode> doesn&#39;t sit on the &quot;Hooks&quot; page with \u003Ccode>useState\u003C\u002Fcode> and \u003Ccode>useEffect\u003C\u002Fcode>. It&#39;s listed separately, under React&#39;s general APIs — and that placement isn&#39;t an accident of alphabetizing.\u003C\u002Fp>",{"id":217,"html":218,"type":137},"b25","\u003Cp>Every other hook comes with the Rules of Hooks: call it unconditionally, at the top level, in the same order, every render. Break that rule with \u003Ccode>useState\u003C\u002Fcode> and React&#39;s internal bookkeeping desyncs — state attaches to the wrong slot. \u003Ccode>use()\u003C\u002Fcode> doesn&#39;t have that problem, because it isn&#39;t tied to a slot in the same way. You can call it inside an \u003Ccode>if\u003C\u002Fcode>, after an early return, or inside a loop:\u003C\u002Fp>",{"id":220,"code":221,"type":152,"language":153,"highlight":222},"b26","function Message({ isLoggedIn, messagePromise }) {\n  if (!isLoggedIn) {\n    return \u003CLoginPrompt \u002F>;\n  }\n\n  \u002F\u002F Calling use() AFTER an early return is exactly what useState forbids.\n  const message = use(messagePromise);\n  return \u003Cp>{message}\u003C\u002Fp>;\n}",[],{"id":224,"html":225,"type":137},"b27","\u003Cp>A real hook here would be a lint error. \u003Ccode>use()\u003C\u002Fcode> is fine with it, because React re-evaluates each call to \u003Ccode>use()\u003C\u002Fcode> on its own, by reading from the thing you passed it, not from a fixed position in a call sequence. The same freedom applies to \u003Ccode>use(SomeContext)\u003C\u002Fcode> — unlike \u003Ccode>useContext\u003C\u002Fcode>, you can read it conditionally, which is genuinely useful for a component that only cares about a context value in one branch.\u003C\u002Fp>",{"id":227,"html":228,"type":137},"b28","\u003Cp>The freedom has a boundary, though: you can&#39;t wrap \u003Ccode>use()\u003C\u002Fcode> in your own \u003Ccode>try\u003C\u002Fcode>\u002F\u003Ccode>catch\u003C\u002Fcode>. If the promise rejects, \u003Ccode>use()\u003C\u002Fcode> throws, and React expects an Error Boundary above it to catch that throw — the same contract as a render that throws for any other reason. If you want to handle the rejection yourself instead, attach \u003Ccode>.catch()\u003C\u002Fcode> to the promise \u003Cem>before\u003C\u002Fem> handing it to \u003Ccode>use()\u003C\u002Fcode>, so it never actually rejects on React&#39;s end.\u003C\u002Fp>",{"id":230,"html":231,"text":231,"type":145,"level":31},"b29","The part worth keeping",{"id":233,"html":234,"type":137},"b30","\u003Cp>\u003Ccode>use()\u003C\u002Fcode> isn&#39;t &quot;useEffect but shorter.&quot; It&#39;s a different contract: you hand it something that eventually has a value, and it pauses the render until that value exists — but only if what you hand it stays recognizably the same thing across renders. Skip the caching and you get the one failure mode worse than the \u003Ccode>useEffect\u003C\u002Fcode> dance you were trying to delete: a spinner that looks broken but is actually working exactly as told, forever.\u003C\u002Fp>",{"id":236,"html":237,"type":137},"b31","\u003Cp>Where in your own code is a promise getting created fresh on every render because moving it up one level felt like overkill? That&#39;s the one to check first — before \u003Ccode>use()\u003C\u002Fcode> finds it for you in production.\u003C\u002Fp>",{"id":239,"html":240,"type":137},"b32","\u003C!-- quiz:start -->",{"id":242,"html":243,"text":243,"type":145,"level":31},"b33","🧠 Test yourself",{"id":245,"html":246,"type":137},"b34","\u003Cp>Think it clicked? \u003Cstrong>\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-use-api-promises-context\u002Fquiz\">Take the 6-question quiz →\u003C\u002Fa>\u003C\u002Fstrong>\u003C\u002Fp>",{"id":248,"html":249,"type":137},"b35","\u003Cp>\u003Cem>Instant feedback, a hint on every question, and an explanation for each answer — right or wrong.\u003C\u002Fem>\u003C\u002Fp>",{"id":251,"html":252,"type":137},"b36","\u003C!-- quiz:end -->",{"id":254,"html":255,"type":137},"b37","\u003C!-- related:start -->",{"id":257,"html":258,"text":258,"type":145,"level":31},"b38","📚 Read next",{"id":260,"type":261,"items":262,"ordered":18},"b39","list",[263,264,265],"\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>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ferror-cause-rethrow-context\">You&#39;re rethrowing errors and losing context. \u003Ccode>Error.cause\u003C\u002Fcode> fixes that.\u003C\u002Fa>","\u003Ca href=\"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusesyncexternalstore-tearing-fix\">Your Custom Hooks Tear in React 18. \u003Ccode>useSyncExternalStore\u003C\u002Fcode> Fixes It.\u003C\u002Fa>",{"id":267,"html":268,"type":137},"b40","\u003C!-- related:end -->",{"id":270,"type":271},"b41","divider",{"id":273,"html":274,"type":137},"b42","\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":276,"html":277,"type":137},"b43","\u003Cp>\u003Cem>Thanks for reading! Let&#39;s stay connected:\u003C\u002Fem>\u003C\u002Fp>",{"id":279,"type":261,"items":280,"ordered":18},"b44",[281,282,283],"⭐ \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>","You rip out a `useEffect`, a `useState`, and a cleanup flag, replace all three with one line of `use()`, and the component looks cleaner than it has in months. Then you refresh the page and the loading spinner never stops. Network tab: the same request, firing again, and again, every few milliseconds, forever.\n\nNothing in the code is wrong, exactly. You just found the one rule `use()` actually enforces — by being the React API that's allowed to break every other rule.\n\n## The dance `use()` was built to end\n\nBefore `use()`, reading an async value inside a component meant writing the same fifteen lines everywhere:\n\n```jsx\nfunction Profile({ userId }) {\n  const [user, setUser] = useState(null);\n  const [loading, setLoading] = useState(true);\n\n  useEffect(() => {\n    let cancelled = false;\n    setLoading(true);\n    fetchUser(userId).then((data) => {\n      if (!cancelled) {\n        setUser(data);\n        setLoading(false);\n      }\n    });\n    return () => { cancelled = true; };\n  }, [userId]);\n\n  if (loading) return \u003CSpinner \u002F>;\n  return \u003CUserCard user={user} \u002F>;\n}\n```\n\nTwo pieces of state tracking one value. A `cancelled` flag so a slow response for the *old* `userId` doesn't overwrite a faster one for the new `userId`. None of it is about showing a user card — it's all plumbing to make `useEffect` behave like something it was never built to be: a way to read an async value.\n\n`use()` reads it directly. No `useEffect`, no `useState`, no race-condition flag:\n\n```jsx\nimport { use, Suspense, useMemo } from \"react\";\n\nfunction Profile({ userPromise }) {\n  const user = use(userPromise);\n  return \u003CUserCard user={user} \u002F>;\n}\n\nfunction ProfilePage({ userId }) {\n  const userPromise = useMemo(() => fetchUser(userId), [userId]);\n  return (\n    \u003CSuspense fallback={\u003CSpinner \u002F>}>\n      \u003CProfile userPromise={userPromise} \u002F>\n    \u003C\u002FSuspense>\n  );\n}\n```\n\n`use(userPromise)` either returns the resolved value or, if the promise is still pending, *suspends* — the same mechanism `React.lazy` uses. React walks up to the nearest `\u003CSuspense>` and shows its fallback instead of rendering `Profile` with nothing. When the promise settles, React re-renders `Profile`, and `use()` just returns the value like it was there all along. One line replaced the whole dance, and the race-condition flag is gone because there's only one state to track: the promise.\n\nBefore you scroll — does anything in that second version look like it could go wrong? Sit with it for a second.\n\n## I simplified it one line further. That's when it broke.\n\nThe `useMemo` felt like an extra step, so I cut it:\n\n```jsx\n\u002F\u002F 🚫 looks identical, isn't\nfunction Profile({ userId }) {\n  const user = use(fetchUser(userId));\n  return \u003CUserCard user={user} \u002F>;\n}\n```\n\nThis is the version that floods the network tab. Here's why: every time `Profile` renders, `fetchUser(userId)` runs again and hands `use()` a *brand-new* promise object — even if `userId` hasn't changed. React has no way to know that this new promise represents \"the same request, still loading.\" It only knows it was just handed a pending promise it's never seen before, so it suspends again. The fallback shows, the promise eventually resolves, `Profile` re-renders, and on *that* render it calls `fetchUser(userId)` one more time — producing yet another new, unseen, pending promise. The loop doesn't stop because nothing ever breaks the chain.\n\n`useMemo` was never decoration. It was the one thing making the promise's *identity* stable across renders — the same promise object came back out every time, as long as `userId` stayed the same — so React could recognize \"I've already seen this one, it's done, here's the value\" instead of \"new pending work, suspend again.\"\n\nThat's the actual rule `use()` enforces, and it's stricter than anything `useEffect` ever asked of you: **the promise has to come from somewhere that caches it.** That's usually one of three places — a parent component that memoizes it (like the `useMemo` above), a Server Component, where the promise can be created fresh each request because the request itself is the cache boundary, or a Suspense-integrated data library (React Query, SWR, Relay) that's already solving this for you. Creating a fresh promise inside the same component that calls `use()` on it, every render, is the one pattern that's never safe.\n\nOne thing worth knowing before you lean on the `useMemo` version in production: React's own docs skip `useMemo` for this and reach straight for a persistent cache (a module-level `Map` keyed by the request, so the same promise comes back no matter what re-renders) — because `useMemo` is documented as a performance optimization, not a guaranteed one. It works in the `ProfilePage`\u002F`Profile` split above specifically because the memo lives in the *parent*, and the parent never suspends. Move that same `useMemo` down into the component that calls `use()`, and the first suspend throws the memoized value away with it — recreating the exact loop you were trying to fix.\n\n\u003C!-- playground:start -->\n\n## 🎮 Try it yourself\n\n**[▶️ Open the interactive playground →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-use-api-promises-context\u002Fplayground)**\n\n_Runs right in your browser — poke at it and watch the concept react live._\n\n\u003C!-- playground:end -->\n\n## Why it's an API, not a hook\n\nHere's the part that's easy to miss if you only skim the React docs: `use()` doesn't sit on the \"Hooks\" page with `useState` and `useEffect`. It's listed separately, under React's general APIs — and that placement isn't an accident of alphabetizing.\n\nEvery other hook comes with the Rules of Hooks: call it unconditionally, at the top level, in the same order, every render. Break that rule with `useState` and React's internal bookkeeping desyncs — state attaches to the wrong slot. `use()` doesn't have that problem, because it isn't tied to a slot in the same way. You can call it inside an `if`, after an early return, or inside a loop:\n\n```jsx\nfunction Message({ isLoggedIn, messagePromise }) {\n  if (!isLoggedIn) {\n    return \u003CLoginPrompt \u002F>;\n  }\n\n  \u002F\u002F Calling use() AFTER an early return is exactly what useState forbids.\n  const message = use(messagePromise);\n  return \u003Cp>{message}\u003C\u002Fp>;\n}\n```\n\nA real hook here would be a lint error. `use()` is fine with it, because React re-evaluates each call to `use()` on its own, by reading from the thing you passed it, not from a fixed position in a call sequence. The same freedom applies to `use(SomeContext)` — unlike `useContext`, you can read it conditionally, which is genuinely useful for a component that only cares about a context value in one branch.\n\nThe freedom has a boundary, though: you can't wrap `use()` in your own `try`\u002F`catch`. If the promise rejects, `use()` throws, and React expects an Error Boundary above it to catch that throw — the same contract as a render that throws for any other reason. If you want to handle the rejection yourself instead, attach `.catch()` to the promise *before* handing it to `use()`, so it never actually rejects on React's end.\n\n## The part worth keeping\n\n`use()` isn't \"useEffect but shorter.\" It's a different contract: you hand it something that eventually has a value, and it pauses the render until that value exists — but only if what you hand it stays recognizably the same thing across renders. Skip the caching and you get the one failure mode worse than the `useEffect` dance you were trying to delete: a spinner that looks broken but is actually working exactly as told, forever.\n\nWhere in your own code is a promise getting created fresh on every render because moving it up one level felt like overkill? That's the one to check first — before `use()` finds it for you in production.\n\n\u003C!-- quiz:start -->\n\n## 🧠 Test yourself\n\nThink it clicked? **[Take the 6-question quiz →](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-use-api-promises-context\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- [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- [You're rethrowing errors and losing context. `Error.cause` fixes that.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Ferror-cause-rethrow-context)\n- [Your Custom Hooks Tear in React 18. `useSyncExternalStore` Fixes It.](https:\u002F\u002Fbestpractic.org\u002Fblog\u002Fusesyncexternalstore-tearing-fix)\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":111,"canonical":286,"description":287},"https:\u002F\u002Fbestpractic.org\u002Fblog\u002Freact-use-api-promises-context","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","01a1fce0-de91-712e-bc98-7454e8586bf2",{"id":290,"locked":18},"01a1fce0-deb4-70b8-939c-4d4382fd91f8",[292],{"id":45,"slug":46,"title":48,"_count":293},{"questions":51},[295],{"locale":13,"slug":46},{"id":45,"slug":46,"title":48,"_count":297,"questionCount":51},{"questions":51},[]]