{"record":{"id":"34e01933ecb1e78d","repo":"facebook/docusaurus","slug":"hook-is-called-outside-the-navbarsecondarymenudis","errorCode":null,"errorMessage":"Hook is called outside the <NavbarSecondaryMenuDisplayProvider>. ","messagePattern":"Hook is called outside the <NavbarSecondaryMenuDisplayProvider>\\. ","errorType":"exception","errorClass":"ReactContextError","httpStatus":null,"severity":"error","filePath":"packages/docusaurus-theme-common/src/contexts/navbarSecondaryMenu/display.tsx","lineNumber":92,"sourceCode":"  }\n  return undefined;\n}\n\n/** Wires the logic for rendering the mobile navbar secondary menu. */\nexport function useNavbarSecondaryMenu(): {\n  /** Whether secondary menu is displayed. */\n  shown: boolean;\n  /**\n   * Hide the secondary menu; fired either when hiding the entire sidebar, or\n   * when going back to the primary menu.\n   */\n  hide: () => void;\n  /** The content returned from the current secondary menu filler. */\n  content: ReactNode;\n} {\n  const value = useContext(Context);\n  if (!value) {\n    throw new ReactContextError('NavbarSecondaryMenuDisplayProvider');\n  }\n  const [shown, setShown] = value;\n  const hide = useCallback(() => setShown(false), [setShown]);\n  const content = useNavbarSecondaryMenuContent();\n\n  return useMemo(\n    () => ({shown, hide, content: renderElement(content)}),\n    [hide, content, shown],\n  );\n}\n","sourceCodeStart":74,"sourceCodeEnd":103,"githubUrl":"https://github.com/facebook/docusaurus/blob/3f483e80e326cc646b54b83d564b3f0c4881b9a6/packages/docusaurus-theme-common/src/contexts/navbarSecondaryMenu/display.tsx#L74-L103","documentation":"Thrown by `useNavbarSecondaryMenuDisplay()` when its context value is missing, i.e. the hook was called outside `<NavbarSecondaryMenuDisplayProvider>`. This provider controls whether the secondary menu is shown and supplies the content; the consumer reads both.","triggerScenarios":"A component calling `useNavbarSecondaryMenuDisplay()` is rendered outside the provider subtree, or the provider was removed from the navbar layout during swizzling.","commonSituations":"Swizzled navbar missing the provider; rendering the secondary menu display component in isolation/tests; portal escaping the provider.","solutions":["Keep `<NavbarSecondaryMenuDisplayProvider>` as an ancestor of the secondary menu display component.","Wrap test renders with the provider.","Diff swizzled layout against upstream after upgrades."],"exampleFix":"// before\n<SecondaryMenuDisplay />\n// after\n<NavbarSecondaryMenuDisplayProvider>\n  <SecondaryMenuDisplay />\n</NavbarSecondaryMenuDisplayProvider>","handlingStrategy":"validation","validationCode":"import {useContext} from 'react';\nimport {Context} from '@docusaurus/theme-common/internal/navbarSecondaryMenu/display';\nfunction useSecondaryMenuDisplaySafe() {\n  const v = useContext(Context);\n  return v ?? null;\n}","typeGuard":null,"tryCatchPattern":"try {\n  const {shown, hide, content} = useNavbarSecondaryMenuDisplay();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('NavbarSecondaryMenuDisplayProvider')) return null;\n  throw e;\n}","preventionTips":["Keep `<NavbarSecondaryMenuDisplayProvider>` above the display consumer.","Wrap test renders with the provider.","Verify provider presence after swizzling."],"tags":["react","context","navbar","secondary-menu","theme-common"],"backgroundTag":null,"analyzedSha":"3f483e80e326cc646b54b83d564b3f0c4881b9a6","analyzedAt":"2026-08-12T13:25:04.382Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}