{"record":{"id":"3452abb0786b14be","repo":"TanStack/table","slug":"usetablecontext-must-be-used-within-an-apptable-3452ab","errorCode":null,"errorMessage":"`useTableContext` must be used within an `AppTable` component. Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.","messagePattern":"`useTableContext` must be used within an `AppTable` component\\. Make sure your component is wrapped with `<table\\.AppTable>\\.\\.\\.</table\\.AppTable>`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/octane-table/src/createTableHook.tsrx","lineNumber":192,"sourceCode":" *   </table.Subscribe>\n * }\n * ```\n */\n\tfunction useTableContext<\n\t\tTData extends RowData = RowData,\n\t\tTSelected = TableState<TFeatures>,\n\t>(): AppOctaneTable<\n\t\tTFeatures,\n\t\tTData,\n\t\tTSelected,\n\t\tTTableComponents,\n\t\tTCellComponents,\n\t\tTHeaderComponents\n\t> {\n\t\tconst table = useContext(TableContext);\n\n\t\tif (!table) {\n\t\t\tthrow new Error('`useTableContext` must be used within an `AppTable` component. ' +\n\t\t\t\t'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.');\n\t\t}\n\n\t\t// The value provided by `<table.AppTable>` is the extended table (the App*\n\t\t// wrapper components and `tableComponents` are Object.assign-ed onto the\n\t\t// same instance `useAppTable` returns), so this asserts the runtime shape.\n\t\treturn table as unknown as AppOctaneTable<\n\t\t\tTFeatures,\n\t\t\tTData,\n\t\t\tTSelected,\n\t\t\tTTableComponents,\n\t\t\tTCellComponents,\n\t\t\tTHeaderComponents\n\t\t>;\n\t}\n\n\t/**\n * Access the cell instance from within an `AppCell` wrapper. Use this in","sourceCodeStart":174,"sourceCodeEnd":210,"githubUrl":"https://github.com/TanStack/table/blob/d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6/packages/octane-table/src/createTableHook.tsrx#L174-L210","documentation":"Octane (React-like) table's `useTableContext` reads `useContext(TableContext)`, which only `<table.AppTable>` provides. When the hook runs outside that provider, context is null and the hook throws immediately. This prevents dereferencing an undefined table later.","triggerScenarios":"Calling `useTableContext()` in a component not rendered inside `<table.AppTable>...</table.AppTable>` — e.g. in a sibling of the table, in a React portal outside the AppTable subtree, or in a helper called before the table component mounts.","commonSituations":"Splitting table-related logic into a custom hook used by a component outside the table tree; rendering table children through a portal; forgetting to wrap the app with `<table.AppTable>` during migration to the App* component API.","solutions":["Render the calling component within `<table.AppTable>` so TableContext is provided.","Pass the table instance as a prop instead of using context for out-of-tree components.","If using portals, keep the portal inside AppTable's React subtree (React portals keep context only from the React tree, not the DOM tree)."],"exampleFix":"// before\nexport function Toolbar() {\n  const table = useTableContext()\n}\n// after\n<table.AppTable table={table}>\n  <Toolbar />\n</table.AppTable>","handlingStrategy":"validation","validationCode":"const table = useContext(TableContext)\nif (!table) {\n  console.warn('Component must be rendered inside <table.AppTable>')\n}","typeGuard":"function hasTableContext(t: unknown): t is NonNullable<typeof t> {\n  return t != null\n}","tryCatchPattern":"try {\n  const table = useTableContext()\n} catch (e) {\n  if (e instanceof Error && e.message.includes('useTableContext')) {\n    // render placeholder or take table via prop instead\n  } else throw e\n}","preventionTips":["Wrap all table-dependent UI inside <table.AppTable>","For toolbars/modals outside the tree, accept the table as a prop","Remember portals keep React context only from the React parent chain","Keep AppTable and hooks from the same package version"],"tags":["react","octane-table","context","missing-provider"],"backgroundTag":"hook-used-outside-provider","analyzedSha":"d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6","analyzedAt":"2026-08-28T21:52:44.679Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}