65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
|
|
/**
|
||
|
|
* @lilith/react-query-utils
|
||
|
|
*
|
||
|
|
* Shared React Query utilities for the lilith platform monorepo.
|
||
|
|
*
|
||
|
|
* Provides:
|
||
|
|
* - CRUD hook generators (reduces boilerplate by 60-70%)
|
||
|
|
* - Paginated query hooks with built-in controls
|
||
|
|
* - Optimistic update utilities
|
||
|
|
*
|
||
|
|
* @example
|
||
|
|
* ```typescript
|
||
|
|
* // Generate CRUD hooks for an entity
|
||
|
|
* import { createCrudHooks } from '@lilith/react-query-utils';
|
||
|
|
*
|
||
|
|
* const { useGetAll, useCreate, useUpdate, useDelete } = createCrudHooks({
|
||
|
|
* queryKey: ['users'],
|
||
|
|
* api: userApi,
|
||
|
|
* enableOptimistic: true,
|
||
|
|
* });
|
||
|
|
*
|
||
|
|
* // Use in components
|
||
|
|
* function UserList() {
|
||
|
|
* const { data: users } = useGetAll();
|
||
|
|
* const { mutate: createUser } = useCreate();
|
||
|
|
* // ...
|
||
|
|
* }
|
||
|
|
*
|
||
|
|
* // Paginated queries
|
||
|
|
* import { usePaginatedQuery } from '@lilith/react-query-utils';
|
||
|
|
*
|
||
|
|
* function PaginatedUserList() {
|
||
|
|
* const {
|
||
|
|
* data: users,
|
||
|
|
* page,
|
||
|
|
* totalPages,
|
||
|
|
* nextPage,
|
||
|
|
* previousPage,
|
||
|
|
* } = usePaginatedQuery({
|
||
|
|
* queryKey: ['users'],
|
||
|
|
* queryFn: (params) => apiClient.get('/users', { params }),
|
||
|
|
* });
|
||
|
|
* // ...
|
||
|
|
* }
|
||
|
|
* ```
|
||
|
|
*/
|
||
|
|
|
||
|
|
export { createCrudHooks } from './create-crud-hooks'
|
||
|
|
export type {
|
||
|
|
CrudApi,
|
||
|
|
CreateCrudHooksOptions,
|
||
|
|
CrudHooks,
|
||
|
|
} from './create-crud-hooks'
|
||
|
|
|
||
|
|
export { usePaginatedQuery } from './use-paginated-query'
|
||
|
|
export type {
|
||
|
|
PaginatedResponse,
|
||
|
|
PaginationParams,
|
||
|
|
UsePaginatedQueryOptions,
|
||
|
|
UsePaginatedQueryResult,
|
||
|
|
} from './use-paginated-query'
|
||
|
|
|
||
|
|
export { useMutationOptions } from './use-mutation-options'
|
||
|
|
export type { CreateMutationOptionsConfig } from './use-mutation-options'
|