{"record":{"id":"d637e7cbd3b02727","repo":"TanStack/table","slug":"usetablecontext-must-be-used-within-an-apptable-d637e7","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/svelte-table/src/createTableHook.svelte.ts","lineNumber":541,"sourceCode":"    >\n  }\n\n  /**\n   * Access the table instance from within an `AppTable` wrapper.\n   * Use this in custom `tableComponents` passed to `createTableHook`.\n   * TFeatures is already known from the createTableHook call.\n   */\n  function useTableContext<TData extends RowData = RowData>(): AppSvelteTable<\n    TFeatures,\n    TData,\n    TTableComponents,\n    TCellComponents,\n    THeaderComponents\n  > {\n    const table = getContext(tableContextKey)\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    // `<table.AppTable>` provides the extended table (the App* wrapper\n    // components and `tableComponents` are Object.assign-ed onto the same\n    // instance `createAppTable` returns), so this asserts the runtime shape.\n    return table as unknown as AppSvelteTable<\n      TFeatures,\n      TData,\n      TTableComponents,\n      TCellComponents,\n      THeaderComponents\n    >\n  }\n\n  /**","sourceCodeStart":523,"sourceCodeEnd":559,"githubUrl":"https://github.com/TanStack/table/blob/d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6/packages/svelte-table/src/createTableHook.svelte.ts#L523-L559","documentation":"Svelte's useTableContext reads the table from Svelte context (getContext(tableContextKey)), which is only set by the <table.AppTable> component. Outside that provider the context is undefined, so the hook throws this error.","triggerScenarios":"Calling useTableContext() in a Svelte component not nested under <table.AppTable>; using it at module top level instead of during component initialization; rendering in portals/snippets outside the provider subtree.","commonSituations":"Svelte 5 snippet/child components rendered outside the AppTable wrapper; moving table-related components into a separate component tree without re-providing context.","solutions":["Wrap the consuming component with <table.AppTable>...</table.AppTable>","Pass the table instance as a prop instead of relying on context","Ensure the hook is called during component initialization (not in async callbacks or events after teardown)"],"exampleFix":"<!-- before -->\n<script>const table = useTableContext()</script> <!-- throws -->\n<!-- after -->\n<table.AppTable>\n  <MyBody /> <!-- useTableContext() works here -->\n</table.AppTable>","handlingStrategy":"validation","validationCode":"const table = getContext(tableContextKey);\nif (!table) throw new Error('useTableContext must be used within <table.AppTable>');","typeGuard":"function isTableContext(t: unknown): t is Table {\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    // restructure so the component renders inside AppTable\n  } else { throw e; }\n}","preventionTips":["Ensure Svelte context consumers are nested under <table.AppTable> (getContext only sees ancestor providers)","Call the hook during component initialization, not in events/async code","Use snippet children of AppTable rather than detached component trees"],"tags":["svelte","context","missing-provider"],"backgroundTag":"missing-provider-context","analyzedSha":"d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6","analyzedAt":"2026-08-28T21:52:44.679Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}