Skip to main content

useTypedData

useTypedData<T, TShaped> builds on top of useData and the typed endpoint definitions found in src/api/endpoints.ts. It takes an endpoint object { url, type }, an optional createShape<TShaped>()([...]), and returns the shaped, typed resource. Source: src/api/fetchData.ts

Signature

useTypedData simply calls useData<TShaped>(apiClient, endpoint?.url, { ...requestConfig, shape: shape?.fields }).

Pattern

  1. Pick an endpoint from src/api/endpoints.ts (these expose type with the expected response)
  2. Build a shape for the response using createShape<typeof endpoint.type>()([...])
  3. Call useTypedData(httpClient, endpoint, shape, { ...options })

Example – FAQ list

Example – Teams list with paging

Notes

  • You can still pass method, data, and queryConfig – these flow through to useData.
  • mockData short-circuits fetching – great for the editor and tests.

See also