Custom React Hooks
Overview
The application uses custom React hooks for data fetching, state management, and UI interactions. All hooks are located in src/hooks/.
Data Fetching Hooks
useUsers
Location: src/hooks/useUsers.ts
Hook for managing user data and operations.
Returns:
users: Array of usersloading: Loading stateerror: Error statepagination: Pagination metadatafetchUsers: Function to fetch users with filtersrefreshUsers: Function to refresh current user list
Usage:
const { users, loading, fetchUsers } = useUsers();
useEffect(() => {
fetchUsers({ page: 1, limit: 10, search: "john" });
}, []);useConferences
Location: src/hooks/useConferences.ts
Hook for managing conference data.
Returns:
conferences: Array of conferencesloading: Loading stateerror: Error statepagination: Pagination metadatafetchConferences: Function to fetch conferencescreateConference: Function to create a conferenceupdateConference: Function to update a conferencedeleteConference: Function to delete a conference
useEvents
Location: src/hooks/useEvents.ts
Hook for managing event data.
Returns:
events: Array of eventsloading: Loading stateerror: Error statepagination: Pagination metadatafetchEvents: Function to fetch eventscreateEvent: Function to create an eventupdateEvent: Function to update an eventdeleteEvent: Function to delete an event
useSpeakers
Location: src/hooks/useSpeakers.ts
Hook for managing speaker data.
Returns:
speakers: Array of speakersloading: Loading stateerror: Error statepagination: Pagination metadatafetchSpeakers: Function to fetch speakerscreateSpeaker: Function to create a speakerupdateSpeaker: Function to update a speakerdeleteSpeaker: Function to delete a speaker
useAgenda
Location: src/hooks/useAgenda.ts
Hook for managing agenda items.
Returns:
agendaItems: Array of agenda itemsloading: Loading stateerror: Error statefetchAgendaItems: Function to fetch agenda items for a conferencecreateAgendaItem: Function to create an agenda itemupdateAgendaItem: Function to update an agenda itemdeleteAgendaItem: Function to delete an agenda item
useQuests
Location: src/hooks/useQuests.ts
Hook for managing quests list.
Returns:
quests: Array of questsloading: Loading stateerror: Error statepagination: Pagination metadatapendingCounts: Pending submission counts per questfetchQuests: Function to fetch queststoggleQuestActive: Function to toggle quest active statusdeleteQuest: Function to delete a quest
useQuestDetail
Location: src/hooks/useQuestDetail.ts
Hook for managing individual quest details.
Returns:
quest: Quest objecttasks: Array of quest tasksloading: Loading stateerror: Error statefetchQuest: Function to fetch quest detailsupdateQuest: Function to update questupdateTasks: Function to update quest tasksupdateQuestAndTasks: Function to update both quest and tasks
useQuestParticipants
Location: src/hooks/useQuestParticipants.ts
Hook for managing quest participants.
Returns:
participants: Array of participantssummary: Participant summary statisticsloading: Loading stateerror: Error statefilters: Current filter statefetchParticipants: Function to fetch participants with filtersapproveRegistration: Function to approve participant registrationrejectRegistration: Function to reject participant registrationassignRewardCodes: Function to assign reward codes
useQuestPendingSubmissions
Location: src/hooks/useQuestPendingSubmissions.ts
Hook for managing pending quest submissions.
Returns:
submissions: Array of pending submissionsloading: Loading stateerror: Error statepagination: Pagination metadatafetchSubmissions: Function to fetch pending submissionsapproveSubmission: Function to approve a submissionrejectSubmission: Function to reject a submission
useQuestReminderTemplates
Location: src/hooks/useQuestReminderTemplates.ts
Hook for managing quest reminder templates.
Returns:
templates: Array of reminder templatesloading: Loading stateerror: Error statefetchTemplates: Function to fetch templatescreateTemplate: Function to create a templateupdateTemplate: Function to update a templatedeleteTemplate: Function to delete a templatesetDefaultTemplate: Function to set default template
Utility Hooks
usePagination
Location: src/hooks/usePagination.ts
Hook for managing pagination state.
Returns:
page: Current page numberlimit: Items per pagesetPage: Function to set pagesetLimit: Function to set limitreset: Function to reset to page 1
Usage:
const { page, limit, setPage, setLimit } = usePagination();useDebounce
Location: src/hooks/useDebounce.ts
Hook for debouncing values (useful for search inputs).
Parameters:
value: Value to debouncedelay: Debounce delay in milliseconds
Returns: Debounced value
Usage:
const [searchTerm, setSearchTerm] = useState("");
const debouncedSearch = useDebounce(searchTerm, 500);use-mobile
Location: src/hooks/use-mobile.ts
Hook for detecting mobile devices.
Returns: Boolean indicating if device is mobile
Usage:
const isMobile = useMobile();Hook Patterns
Error Handling
All data fetching hooks follow a consistent error handling pattern:
- Catch errors and set error state
- Display toast notifications for user feedback
- Log errors to console for debugging
Loading States
All hooks manage loading states to show loading indicators in UI.
Data Refreshing
Most hooks provide refresh functions to refetch data after mutations.
Best Practices
- Always handle loading and error states in components using hooks
- Use debounced search for better performance
- Refresh data after mutations (create, update, delete)
- Handle pagination properly with usePagination hook
- Clean up any subscriptions or timers in useEffect cleanup functions