useOne is a modified version of TanStack Query’s useQuery for retrieving a single record from a resource.
It uses the getOne method from the dataProvider.
Usage
Parameters
Resource name for API data interactions. If not provided, it will be inferred from the route.
ID of the record to fetch. Can be a
string or number.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, params) => OpenNotificationParams | false)
Success notification configuration. Set to
false to disable.errorNotification
OpenNotificationParams | false | ((error, params) => OpenNotificationParams | false)
Error notification configuration. Set to
false to disable.Live/Realtime mode configuration.
Callback to handle live events.
Additional parameters for live queries.
Configuration for loading overtime behavior.
Return Values
The fetched record data.
TanStack Query’s
useQuery return object.Loading overtime information.
Examples
Basic Usage
Conditional Fetching
With Meta Data
With Data Transformation
With Multiple Data Providers
Handling Loading and Error States
Manual Refetch
Type Parameters
TQueryFnData- Result data type returned by the query function. ExtendsBaseRecord.TError- Custom error type that extendsHttpError.TData- Result data type returned by theselectfunction. ExtendsBaseRecord. Defaults toTQueryFnData.
FAQ
How do I prevent the query from running automatically?
How do I prevent the query from running automatically?
Use the
queryOptions.enabled parameter:What happens if the id is undefined?
What happens if the id is undefined?
The query will be automatically disabled until
id is defined. This prevents unnecessary API calls.Can I use this hook outside of a resource context?
Can I use this hook outside of a resource context?
Yes, you can explicitly provide the
resource parameter: