UNPKG

react-antd-admin-panel

Version:

Modern TypeScript-first React admin panel builder with Ant Design 6

78 lines 2.39 kB
/** * HTTP methods supported by usePost */ export type UsePostMethod = 'POST' | 'PUT' | 'PATCH' | 'DELETE'; /** * Options for the usePost hook */ export interface UsePostOptions<_TBody, TResponse> { /** The URL to send the request to */ url: string; /** HTTP method (default: POST) */ method?: UsePostMethod; /** Request headers */ headers?: Record<string, string>; /** Callback on success */ onSuccess?: (data: TResponse) => void; /** Callback on error */ onError?: (error: Error) => void; } /** * Return type for the usePost hook */ export interface UsePostResult<TBody, TResponse> { /** Execute the request with the given body */ execute: (body?: TBody) => Promise<TResponse | undefined>; /** Whether a request is in progress */ submitting: boolean; /** Error if request failed */ error: Error | undefined; /** Response data from the last successful request */ data: TResponse | undefined; /** Reset state to initial values */ reset: () => void; /** Abort the current request */ abort: () => void; } /** * usePost - React hook for POST/PUT/PATCH/DELETE requests * * @template TBody - Request body type * @template TResponse - Response data type * @param options - Hook options * @returns Hook result with execute function, submitting state, and data * * @example * ```tsx * // Basic POST * const { execute, submitting } = usePost<CreateUserDto, User>({ * url: '/api/users', * onSuccess: (user) => navigate(`/users/${user.id}`), * }); * await execute({ name: 'John', email: 'john@example.com' }); * * // PUT request * const { execute, submitting } = usePost<UpdateUserDto, User>({ * url: '/api/users/123', * method: 'PUT', * }); * * // DELETE request * const { execute, submitting } = usePost<void, void>({ * url: '/api/users/123', * method: 'DELETE', * onSuccess: () => message.success('Deleted'), * }); * await execute(); * * // With FormData for file upload * const { execute, submitting } = usePost<FormData, UploadResponse>({ * url: '/api/upload', * }); * const formData = new FormData(); * formData.append('file', file); * await execute(formData); * ``` */ export declare function usePost<TBody = any, TResponse = any>(options: UsePostOptions<TBody, TResponse>): UsePostResult<TBody, TResponse>; //# sourceMappingURL=usePost.d.ts.map