{"record":{"id":"3303bc22c7c65eea","repo":"facebook/react","slug":"373","errorCode":"373","errorMessage":"This Hook is not supported in Server Components.","messagePattern":"This Hook is not supported in Server Components\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server/src/ReactFlightHooks.js","lineNumber":107,"sourceCode":"  useHostTransitionStatus: unsupportedHook as any,\n  useFormState: unsupportedHook as any,\n  useActionState: unsupportedHook as any,\n  useOptimistic: unsupportedHook as any,\n  useMemoCache(size: number): Array<any> {\n    const data = new Array<any>(size);\n    for (let i = 0; i < size; i++) {\n      data[i] = REACT_MEMO_CACHE_SENTINEL;\n    }\n    return data;\n  },\n  useCacheRefresh(): <T>(?() => T, ?T) => void {\n    return unsupportedRefresh;\n  },\n  useEffectEvent: unsupportedHook as any,\n};\n\nfunction unsupportedHook(): void {\n  throw new Error('This Hook is not supported in Server Components.');\n}\n\nfunction unsupportedRefresh(): void {\n  throw new Error(\n    'Refreshing the cache is not supported in Server Components.',\n  );\n}\n\nfunction unsupportedContext(): void {\n  throw new Error('Cannot read a Client Context from a Server Component.');\n}\n\nfunction useId(): string {\n  if (currentRequest === null) {\n    throw new Error('useId can only be used while React is rendering');\n  }\n  const id = currentRequest.identifierCount++;\n  // use 'S' for Flight components to distinguish from 'R' and 'r' in Fizz/Client","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server/src/ReactFlightHooks.js#L89-L125","documentation":"The RSC (Flight) hook dispatcher implements only server-safe hooks: use, useCallback, useMemo, useId, useContext (server contexts), useDebugValue, useMemoCache, and useCacheRefresh. Stateful and interactive hooks — useState, useReducer, useRef, useEffect, useLayoutEffect, useInsertionEffect, useImperativeHandle, useDeferredValue, useTransition, useSyncExternalStore, useActionState/useFormState, useOptimistic, useEffectEvent, useHostTransitionStatus — all throw via unsupportedHook (error code 373).","triggerScenarios":"Calling any of those hooks in a module React renders as a Server Component — a file without the 'use client' directive — including hooks reached through imports from shared hook libraries.","commonSituations":"Adding interactivity to a file the framework renders on the server (Next.js app router defaults pages/layouts to server components); importing a hook library not marked as client code; forgetting the 'use client' directive at the top of an interactive component.","solutions":["Add 'use client' as the very first statement of the file that uses stateful or interactive hooks","Split the interactive part into its own client component and render it from the server component","If the logic must stay on the server, replace the hook with a server-safe pattern: props, await, cache(), or use()"],"exampleFix":"// before (server component by default)\nexport function Counter() {\n  const [n, setN] = useState(0); // throws in a Server Component\n  return <button onClick={() => setN(n + 1)}>{n}</button>;\n}\n\n// after: Counter.js\n'use client';\nexport function Counter() {\n  const [n, setN] = useState(0);\n  return <button onClick={() => setN(n + 1)}>{n}</button>;\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Learn the server-safe hook set: use, useId, useCacheRefresh, useMemoCache, useCallback, useMemo, useContext","Put 'use client' at the top of every interactive file before adding hooks","Check hook libraries for 'use client' directives before importing them into server components"],"tags":["server-components","hooks","use-client","rsc"],"backgroundTag":"hooks-unsupported-in-server-components","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}