{"record":{"id":"f9d9a4978b8ecc3a","repo":"react-navigation/react-navigation","slug":"couldn-t-find-a-navigation-object-is-your-compone-f9d9a4","errorCode":null,"errorMessage":"Couldn't find a navigation object. Is your component inside NavigationContainer?","messagePattern":"Couldn't find a navigation object\\. Is your component inside NavigationContainer\\?","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/native/src/useLinkBuilder.tsx","lineNumber":101,"sourceCode":"      options?.enabled,\n      options?.config,\n      isScreen,\n      focusedRouteState,\n      getPathFromStateHelper,\n    ]\n  );\n\n  return buildHref;\n}\n\n/**\n * Helper to build a navigation action from a href based on the linking options.\n */\nexport function useBuildAction() {\n  const navigation = React.use(NavigationContainerRefContext);\n\n  if (navigation === undefined) {\n    throw new Error(\n      \"Couldn't find a navigation object. Is your component inside NavigationContainer?\"\n    );\n  }\n\n  const { options } = React.use(LinkingContext);\n\n  const getActionFromStateHelper =\n    options?.getActionFromState ?? getActionFromState;\n\n  const buildAction = React.useCallback(\n    (href: string) => {\n      const rootState = navigation.getRootState();\n\n      const state = getStateFromHref(href, options, rootState);\n\n      if (state) {\n        const action =\n          getActionFromStateHelper(state, options?.config) ??","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/react-navigation/react-navigation/blob/ab1319d6bbf05eae8dc25e33cbf4dc56494e0f0c/packages/native/src/useLinkBuilder.tsx#L83-L119","documentation":"useBuildAction (used by useLinkBuilder's buildAction) reads the NavigationContainerRefContext to get the root navigation object for constructing link actions. If the context is undefined, the hook is being called outside a NavigationContainer, so it cannot resolve navigation state and the library throws.","triggerScenarios":"Calling useLinkBuilder/useBuildAction in a component rendered outside <NavigationContainer>, e.g. in a root App component above the container, in a modal mounted at the app root, or in tests without a container wrapper.","commonSituations":"Custom link buttons/buttons placed outside the navigator tree; components extracted to app root for layout reasons; Storybook/tests rendering link components standalone.","solutions":["Move the component (or the hook call) inside the component tree under <NavigationContainer>, ideally inside a screen.","Ensure NavigationContainer wraps all components that call useLinkBuilder before any hook usage.","If the component must live outside, pass a href builder down as props from an in-tree component.","In tests/Storybook, wrap the component in a NavigationContainer (with a minimal navigator) before rendering."],"exampleFix":"// before\nfunction App() {\n  const buildAction = useBuildAction();\n  return <NavigationContainer>{/* ... */}</NavigationContainer>;\n}\n// after\nfunction App() {\n  return (\n    <NavigationContainer>\n      <LinkButton />  // hook used inside the container\n    </NavigationContainer>\n  );\n}","handlingStrategy":"type-guard","validationCode":"const nav = React.use(NavigationContainerRefContext);\nif (nav === undefined) {\n  // don't call useBuildAction-dependent logic; render a disabled link\n}","typeGuard":"function isInsideNavigationContainer(): boolean {\n  return React.use(NavigationContainerRefContext) !== undefined;\n}","tryCatchPattern":"try {\n  const action = buildAction(href);\n} catch (e) {\n  if (String(e.message).includes(\"Couldn't find a navigation object\")) {\n    // render non-navigating fallback (disabled button / external Linking.openURL)\n  } else throw e;\n}","preventionTips":["Only call useLinkBuilder/useBuildAction in components under <NavigationContainer>.","Keep link-building components inside screens, not at the app root.","Wrap Storybook/test renders in a NavigationContainer.","Lift the hook call into an in-tree component and pass results down as props."],"tags":["navigation","hooks","context","react-navigation"],"backgroundTag":"missing-navigation-context","analyzedSha":"ab1319d6bbf05eae8dc25e33cbf4dc56494e0f0c","analyzedAt":"2026-08-31T14:46:19.520Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}