# Frontend Utility Hooks & Components Guide Complete TypeScript/TSX utilities that mirror the backend helpers and make frontend development much easier. ## Table of Contents 1. [Hooks](#hooks) - [usePaginatedData](#usepaginateddata) - [useApiMutation](#useapimutation) - [useFormValidation](#useformvalidation) - [useQueryBuilder](#usequerybuilder) - [useToast](#usetoast) - [useBatchSelection](#usebatchselection) 2. [Components](#components) - [DataTable](#datatable) - [ToastContainer](#toastcontainer) 3. [Utilities](#utilities) - [Export Functions](#export-functions) 4. [Complete Example](#complete-example) --- ## Hooks ### usePaginatedData **Purpose:** Fetch paginated data with search, sort, and filters in one line. **Features:** - Automatic pagination management - Search functionality - Sorting - Filtering - Loading and error states - Works seamlessly with backend QueryParser ```tsx import { usePaginatedData } from '../hooks/usePaginatedData'; interface Article { id: number; title: string; published: boolean; } function ArticleList() { const { data: articles, meta, loading, error, setPage, setSearch, setSort, setFilters, refresh, } = usePaginatedData
('/articles', { page_size: 20, }); return (
setSearch(e.target.value)} placeholder="Search..." /> {loading &&

Loading...

} {error &&

Error: {error}

} {meta && ( )}
); } ``` ### useApiMutation **Purpose:** Handle POST, PUT, PATCH, DELETE requests with loading states. **Features:** - Automatic loading states - Error handling - Success tracking - TypeScript support ```tsx import { useApiPost, useApiDelete } from '../hooks/useApiMutation'; function ArticleForm() { // Create article const { mutate: createArticle, loading, error, success } = useApiPost
('/articles'); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); const article = await createArticle({ title: 'New Article', content: 'Content here...', }); if (article) { console.log('Created:', article); } }; // Delete article const deleteArticle = useApiDelete((data: { id: number }) => `/articles/${data.id}`); const handleDelete = async (id: number) => { await deleteArticle.mutate({ id }); }; return (
{error &&

{error}

} {success &&

Article created!

}
); } ``` ### useFormValidation **Purpose:** Form validation with built-in rules and error messages. **Features:** - Required, min/max length, pattern, email, URL validators - Custom validators - Automatic error messages - Touch tracking - Easy integration with forms ```tsx import { useFormValidation } from '../hooks/useFormValidation'; interface ArticleForm { title: string; content: string; email: string; url: string; } function CreateArticleForm() { const { values, errors, touched, handleChange, handleBlur, handleSubmit, } = useFormValidation( { title: '', content: '', email: '', url: '', }, { title: { required: true, min: 3, max: 200 }, content: { required: true, min: 10 }, email: { required: true, email: true }, url: { url: true }, } ); const onSubmit = async (data: ArticleForm) => { console.log('Valid data:', data); // Call API here }; return (
{touched.title && errors.title && ( {errors.title} )}