Overview
SIGEAC uses React Query (@tanstack/react-query) for all server data fetching, providing caching, synchronization, and optimistic updates.Architecture
Query Pattern
Create a custom hook for each data fetching operation.Basic Query
hooks/general/clientes/useGetClients.ts
hooks/general/clientes/useGetClients.ts:1
Using the Query Hook
components/ClientList.tsx
Query with Parameters
hooks/general/clientes/useGetClientById.ts
Mutation Pattern
Create mutations for data modification operations.Create Mutation
actions/general/clientes/actions.ts
actions/general/clientes/actions.ts:16
Update Mutation
actions/general/clientes/actions.ts
actions/general/clientes/actions.ts:75
Delete Mutation
actions/general/clientes/actions.ts
actions/general/clientes/actions.ts:47
Using Mutations
components/ClientForm.tsx
Axios Configuration
The Axios instance is configured with interceptors:lib/axios.ts
lib/axios.ts:1
Query Options
Stale Time
Control how long data is considered fresh:Cache Time
Control how long unused data stays in cache:Enabled
Conditionally enable queries:Refetch Intervals
Automatically refetch data:Error Handling
Query Errors
Mutation Errors
Loading States
Query Loading
Mutation Loading
Pagination
hooks/general/clientes/useGetClientsPaginated.ts
Infinite Queries
Dependent Queries
Fetch data that depends on other data:Optimistic Updates
Update UI before server confirms:Best Practices
Use proper query keys
Use proper query keys
Include all dependencies in query keys:
Enable queries conditionally
Enable queries conditionally
Only run queries when you have required data:
Handle loading and error states
Handle loading and error states
Always handle loading and error states:
Invalidate queries after mutations
Invalidate queries after mutations
Always invalidate related queries:
Next Steps
Custom Hooks
Learn to create reusable custom hooks
API Integration
Integrate with backend APIs
