TanStack/table · error

`useTableContext` must be used within an `AppTable` componen

Error message

`useTableContext` must be used within an `AppTable` component. Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.

What it means

`useTableContext` in the Solid adapter reads the Solid context provided by `<table.AppTable>`. When no provider exists above the calling component, the context is undefined and this error is thrown. It prevents table APIs from being used without a table instance.

Source

Thrown at packages/solid-table/src/createTableHook.tsx:669

   *           <button onClick={() => table.nextPage()}>Next</button>
   *         </div>
   *       )}}
   *     </table.Subscribe>
   *   )
   * }
   * ```
   */
  function useTableContext<TData extends RowData = RowData>(): AppSolidTable<
    TFeatures,
    TData,
    TTableComponents,
    TCellComponents,
    THeaderComponents
  > {
    const table = useContext(TableContext)

    if (!table) {
      throw new Error(
        '`useTableContext` must be used within an `AppTable` component. ' +
          'Make sure your component is wrapped with `<table.AppTable>...</table.AppTable>`.',
      )
    }

    // The value provided by `<table.AppTable>` is the extended table (the App*
    // wrapper components and `tableComponents` are Object.assign-ed onto the same
    // instance `createAppTable` returns), so this asserts the runtime shape.
    return table as unknown as AppSolidTable<
      TFeatures,
      TData,
      TTableComponents,
      TCellComponents,
      THeaderComponents
    >
  }

  /**

View on GitHub (pinned to d01c01bedb)

Solutions

  1. Wrap the consuming component with `<table.AppTable table={table}>...</table.AppTable>`.
  2. Move the component into AppTable's children within the same reactive root.
  3. Dedupe solid-table versions so the context module is shared.
  4. Read the context directly (`useContext(TableContext)`) and handle undefined if usage is optional.

Example fix

// before
function RowCount() {
  const table = useTableContext()
  return <span>{table.getRowModel().rows.length}</span>
}

// after
<table.AppTable table={table}>
  <RowCount />
</table.AppTable>
Defensive patterns

Strategy: validation

Validate before calling

import { useContext } from 'solid-js'
import { TableContext } from '@your-scope/solid-table'

function useSafeTable() {
  const table = useContext(TableContext)
  if (!table) {
    console.error('useTableContext requires <table.AppTable> above this component')
  }
  return table
}

Type guard

function hasTable<T>(t: T | null | undefined): t is T {
  return t != null
}

Try / catch

try {
  const table = useTableContext()
  // use table
} catch (err) {
  if (err instanceof Error && err.message.includes('useTableContext')) {
    return null // not inside <table.AppTable>
  }
  throw err
}

Prevention

When it happens

Trigger: Calling `useTableContext()` outside `<table.AppTable table={table}>`'s subtree; rendering consumers via Portal (solid-js/web) outside the provider; duplicated solid-table installs with separate context identities.

Common situations: Custom Solid toolbar/control components placed outside AppTable; test harnesses mounting only the child; refactors that extracted components from AppTable children.

Related errors


AI-assisted analysis of TanStack/table@d01c01bedb (2026-08-28). Data as JSON: /api/errors/7c31191c4f0ac678. Report an issue: GitHub.