Skip to Content
TelamonJS

Hooks

React hooks exported by the UI package, grouped by what they do

Every hook below is exported by the root barrel (@telamonjs/ui) unless a different entry point is named. All of them are client-side: call them from a component or file marked 'use client'.

Data fetching comes from React Query, not from this package

useQuery, useMutation and useQueryClient are not re-exported. Import them from @tanstack/react-query directly — a second copy of React Query breaks the app's QueryClient ("No QueryClient set"). The same applies to next-intl.


Table state

HookSignatureUse it for
useTableState(tableId: string) => TableStateRead the whole persisted state of one DataTable/ListPage
useTableSorting(tableId: string) => SortingStateSubscribe to the sorting slice only

URL state

HookUse it for
useUrlSyncRead/write query params (getParam, setParam, setParams)
useTabUrlSyncActive tab kept in the URL, with validation
useUrlFiltersListPage "Filters" panel (selectors, date ranges, text) kept in the URL

CRUD data

These wrap React Query around a CrudConfig. ListPage already uses them — reach for them only when you build a custom screen on top of the same config.

HookUse it for
useInfiniteListQueryInfinite-scroll pages from config.query.queryFn
useCrudMutationsCreate / update / delete mutations from config.mutations, with cache invalidation
useRecordRefreshReload the record behind the nearest dialog that provides one; null outside it

Forms

HookUse it for
useForm, useForms, useFormStoreZustand form store used by ZustandForm
useFormDraftPersist an unsaved draft and restore it
useUnsavedChangesGuardConfirm before discarding a dirty form (setDirty, guard, reset, dialog)
useWatch, useFormContextRe-exported from the same react-hook-form copy the forms use

Layout and app state

HookUse it for
useShellPagePage title/actions inside AdminShell
useIsMobileResponsive breakpoint

Utilities

HookUse it for
toastShow a toast: toast({ title, description, variant })
useDebounceuseDebounce(value, delay = 300) → debounced value
useAnimatedCounterAnimate a number in dashboards
useText, useFormatResolve an I18nText slot and format dates/numbers in the active locale

Example: a selector-based store read

In a component, subscribe to the smallest slice you need; selecting the whole store re-renders on every change. Inside a custom hook that takes the key as a parameter, do the opposite: see Zustand Selector Pattern.

'use client'

import { useFormStore } from '@telamonjs/ui'

// Re-renders only when this form's `name` changes
const name = useFormStore(state => state.forms['user-form']?.name)

Example: toast after a mutation

'use client'

import { useMutation } from '@tanstack/react-query'
import { toast } from '@telamonjs/ui'

export function useDeleteUser() {
  return useMutation({
    mutationFn: (id: string) => usersApi.delete(id),
    onSuccess: () => toast({ title: 'User deleted' }),
    onError: () => toast({ title: 'Delete failed', variant: 'destructive' }),
  })
}

On this page