{"record":{"id":"40b59e29a3a8f4f6","repo":"TanStack/table","slug":"usetablecontext-must-be-used-within-an-apptable","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/createTableHookContexts.ts","lineNumber":83,"sourceCode":"  // intentionally loosely typed (`any` features); the `TFeatures` typing is\n  // layered on by the hooks below.\n  const tableContext = createContext<OctaneTable<any, any> | null>(null)\n  const cellContext = createContext<Cell<any, any, any> | null>(null)\n  const headerContext = createContext<Header<any, any, any> | null>(null)\n\n  /**\n   * Access the table instance from within an `AppTable` wrapper bound to these\n   * scoped contexts. `TFeatures` is known; the registered component maps are\n   * not (see {@link createTableHookContexts}).\n   */\n  function useTableContext<TTableData extends RowData = TData>(): OctaneTable<\n    TFeatures,\n    TTableData\n  > {\n    const table = useContext(tableContext)\n\n    if (!table) {\n      throw new Error(\n        '`useTableContext` must be used within an `AppTable` component. ' +\n          'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',\n      )\n    }\n\n    return table as unknown as OctaneTable<TFeatures, TTableData>\n  }\n\n  /**\n   * Access the cell instance from within an `AppCell` wrapper bound to these\n   * scoped contexts.\n   */\n  function useCellContext<TValue extends CellData = CellData>(): Cell<\n    TFeatures,\n    any,\n    TValue\n  > {\n    const cell = useContext(cellContext)","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/TanStack/table/blob/d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6/packages/octane-table/src/createTableHookContexts.ts#L65-L101","documentation":"Octane's useTableContext reads the table from React context. If no table was provided, the caller is not rendering inside the <table.AppTable> provider component, so the hook throws this descriptive error rather than returning null.","triggerScenarios":"Calling the table hook's useTableContext() from a component not nested under <table.AppTable>, or after the AppTable provider was removed/renamed in the component tree.","commonSituations":"Using table sub-hooks in standalone/portal components; rendering cells outside the table tree (e.g. modals via portals without passing context); copy-pasted hook usage from examples missing the AppTable wrapper.","solutions":["Wrap the consuming component in the provider: <table.AppTable>...</table.AppTable>","Pass the table instance explicitly as a prop instead of relying on context for out-of-tree components","Move the hook call into a component rendered within the AppTable subtree"],"exampleFix":"// before\nconst table = useTableContext(); // throws outside provider\n// after\n<table.AppTable>\n  <MyBody /> // useTableContext() works here\n</table.AppTable>","handlingStrategy":"validation","validationCode":"// render-time check\nif (!isWithinAppTable()) throw new Error('useTableContext requires <table.AppTable>');","typeGuard":"function isTableContext(t: unknown): t is OctaneTable {\n  return !!t && typeof t === 'object' && 'getRowModel' in t;\n}","tryCatchPattern":"try {\n  const table = useTableContext();\n} catch (e) {\n  if (e.message.includes('AppTable')) {\n    // render fallback without context or restructure tree\n  } else { throw e; }\n}","preventionTips":["Always place context-consuming components inside <table.AppTable>","Prefer passing the table instance as a prop for out-of-tree components (portals/modals)","Add dev assertions when wrapping components that depend on table context"],"tags":["react","context","missing-provider","octane"],"backgroundTag":"missing-provider-context","analyzedSha":"d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6","analyzedAt":"2026-08-28T21:52:44.679Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}