useCustom is a modified version of TanStack Query’s useQuery for custom requests that don’t fit into the standard CRUD operations.
It uses the custom method from the dataProvider.
Usage
Parameters
The URL endpoint for the custom request.
HTTP method for the request.
Configuration for the request.
Meta data for the dataProvider. Can be used to pass additional parameters to data provider methods.
If there is more than one
dataProvider, you should specify which one to use.TanStack Query’s
useQuery options.successNotification
OpenNotificationParams | false | ((data, config) => OpenNotificationParams | false)
Success notification configuration. Set to
false to disable.errorNotification
OpenNotificationParams | false | ((error, config) => OpenNotificationParams | false)
Error notification configuration. Set to
false to disable.Configuration for loading overtime behavior.
Return Values
Simplified result object.
TanStack Query’s
useQuery return object.Loading overtime information.
Examples
Basic GET Request
POST Request with Payload
With Query Parameters
With Custom Headers
With Filters and Sorters
Conditional Fetching
With Data Transformation
Multiple Data Providers
Fetching External API
Aggregation or Analytics Query
GraphQL Query
With Error Handling
Manual Refetch
Type Parameters
TQueryFnData- Result data type returned by the query function. ExtendsBaseRecord.TError- Custom error type that extendsHttpError.TQuery- Type of query parameters.TPayload- Type of request payload/body.TData- Result data type returned by theselectfunction. ExtendsBaseRecord. Defaults toTQueryFnData.
FAQ
When should I use useCustom instead of other hooks?
When should I use useCustom instead of other hooks?
Use
useCustom when:- You need to call a custom endpoint that doesn’t fit CRUD operations
- You’re fetching aggregated data or analytics
- You’re calling external/third-party APIs
- You need custom request/response handling
How do I send request body with GET request?
How do I send request body with GET request?
GET requests typically don’t have a body. Use
query for query parameters:Can I use this for mutations?
Can I use this for mutations?
For read operations, use
useCustom. For mutations (POST/PUT/PATCH/DELETE that modify data), consider using useCustomMutation instead for better semantics and automatic invalidation support.Does this support the dataProvider's custom method?
Does this support the dataProvider's custom method?
Yes,
useCustom uses the custom method from your dataProvider. Make sure your dataProvider implements this method.How do I handle authentication?
How do I handle authentication?
Authentication is typically handled by your dataProvider or HTTP client. You can also pass custom headers: