{"record":{"id":"f5a42ec543f0d188","repo":"TanStack/table","slug":"usecellcontext-must-be-used-within-an-appcell-f5a42e","errorCode":null,"errorMessage":"`useCellContext` must be used within an `AppCell` component. Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.","messagePattern":"`useCellContext` must be used within an `AppCell` component\\. Make sure your component is wrapped with `<table\\.AppCell cell=(.+?)>\\.\\.\\.</table\\.AppCell>`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/svelte-table/src/createTableHook.svelte.ts","lineNumber":573,"sourceCode":"      THeaderComponents\n    >\n  }\n\n  /**\n   * Access the cell instance from within an `AppCell` wrapper.\n   * Use this in custom `cellComponents` passed to `createTableHook`.\n   * TFeatures is already known from the createTableHook call.\n   */\n  function useCellContext<TValue extends CellData = CellData>(): Cell<\n    TFeatures,\n    any,\n    TValue\n  > &\n    TCellComponents & { FlexRender: typeof FlexRenderSvelte } {\n    const cell = getContext(cellContextKey)\n\n    if (!cell) {\n      throw new Error(\n        '`useCellContext` must be used within an `AppCell` component. ' +\n          'Make sure your component is wrapped with `<table.AppCell cell={cell}>...</table.AppCell>`.',\n      )\n    }\n\n    // `<table.AppCell>` Object.assign-es `cellComponents` and `FlexRender` onto\n    // the same cell instance it puts in context, so this asserts the runtime\n    // shape.\n    return cell as unknown as Cell<TFeatures, any, TValue> &\n      TCellComponents & { FlexRender: typeof FlexRenderSvelte }\n  }\n\n  /**\n   * Access the header instance from within an `AppHeader` or `AppFooter` wrapper.\n   * Use this in custom `headerComponents` passed to `createTableHook`.\n   * TFeatures is already known from the createTableHook call.\n   */\n  function useHeaderContext<TValue extends CellData = CellData>(): Header<","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/TanStack/table/blob/d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6/packages/svelte-table/src/createTableHook.svelte.ts#L555-L591","documentation":"Svelte's useCellContext reads the cell from Svelte context set by <table.AppCell cell={cell}>. If context is undefined, the hook is called outside an AppCell wrapper and throws this error.","triggerScenarios":"Calling useCellContext() from a component not rendered via <table.AppCell cell={cell}>; reusing a cell component as a header/footer; snippet components instantiated outside the cell subtree.","commonSituations":"Extracted custom cell components rendered directly in markup; moving cell content into modals/portals without the AppCell wrapper; copy-pasted usage across slots.","solutions":["Render the component inside <table.AppCell cell={cell}>...</table.AppCell>","Pass the cell explicitly as a prop if it must render outside the AppCell subtree","Use the matching hook for the slot (useHeaderContext for headers, useTableContext at table level)"],"exampleFix":"<!-- before -->\n<script>const cell = useCellContext()</script> <!-- throws -->\n<!-- after -->\n<table.AppCell cell={cell}>\n  <MyCellContent /> <!-- useCellContext() works here -->\n</table.AppCell>","handlingStrategy":"validation","validationCode":"const cell = getContext(cellContextKey);\nif (!cell) throw new Error('useCellContext must be used within <table.AppCell cell={cell}>');","typeGuard":"function isCell(c: unknown): c is Cell<any, any, any> {\n  return !!c && typeof c === 'object' && 'column' in c && 'row' in c;\n}","tryCatchPattern":"try {\n  const cell = useCellContext();\n} catch (e) {\n  if (e.message.includes('AppCell')) {\n    // accept the cell as a prop instead\n  } else { throw e; }\n}","preventionTips":["Render cell-consuming components only inside <table.AppCell cell={cell}>","Do not reuse cell components in header/footer slots without the right wrapper","Prefer explicit cell props for portal/modal rendering"],"tags":["svelte","context","missing-provider","cell"],"backgroundTag":"missing-provider-context","analyzedSha":"d01c01bedbab0ff6c2641f18b2fc9a11545d9bf6","analyzedAt":"2026-08-28T21:52:44.679Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}