useTableStructure

Fetch table structure before mounting ApiTablesController

File: ./ApiTables/hooks/useTableStructure.ts

This hook runs on your feature page — outside ApiTablesProvider. It is the first code that talks to the backend when a table page loads.

Why a separate hook?

Structure lives in local React state on the page, not in table Redux yet. Only after you pass table={tableStructure} into ReactApiTable does the provider hydrate Redux slices.

Junior takeaway

Call getTableStructure in useEffect on mount. Wait for tableStructureLoading === false before rendering ReactApiTable.

API

const { getTableStructure, tableStructure, tableStructureLoading } = useTableStructure();
ReturnDescription
getTableStructure({ table, params? })GET structure via axiosTable
tableStructureResponse data — columns, filters, actions, tableName, …
tableStructureLoadingtrue until first request completes

Request details

  • table — full path or relative path to load-table endpoint
  • params — optional object forwarded to backend (scoped tables)
  • Header ln: locale from useLocale() for translated column labels

Minimal usage

useEffect(() => {
  getTableStructure({
    table: '/api-table/control-tables/load-table/orders',
    params: { warehouseId },
  });
}, [warehouseId]);

When warehouseId changes, refetch structure so backend can return different columns/filters.

Common mistakes

MistakeResult
Skip loading gateEmpty or crashing table
Use query-table URLWrong response shape
Hard-code columns from structureDefeats server-driven model
Forget locale headerUntranslated labels (backend dependent)

On this page