useMany is a modified version of TanStack Query’s useQuery for retrieving multiple records by their IDs from a resource.
It uses the getMany method from the dataProvider if available, or falls back to multiple getOne calls.
Usage
Parameters
Resource name for API data interactions.
Array of record IDs to fetch. Each ID 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, ids) => OpenNotificationParams | false)
Success notification configuration. Set to
false to disable.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
Simplified result object.
TanStack Query’s
useQuery return object.Loading overtime information.
Examples
Basic Usage
With Dynamic IDs
Fetching Related Data
With Meta Data
With Data Transformation
Creating a Lookup Map
Handling Empty IDs
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
What happens if the data provider doesn't support getMany?
What happens if the data provider doesn't support getMany?
If the
getMany method is not implemented in your data provider, Refine will automatically fall back to making multiple getOne requests in parallel.How do I prevent the query from running with empty IDs?
How do I prevent the query from running with empty IDs?
Use the
queryOptions.enabled parameter:Is the order of results guaranteed to match the order of IDs?
Is the order of results guaranteed to match the order of IDs?
The order depends on your data provider implementation. Most data providers will return results in the same order as the requested IDs, but this is not guaranteed by Refine.
What's the performance impact of using useMany vs multiple useOne calls?
What's the performance impact of using useMany vs multiple useOne calls?
useMany is much more efficient as it makes a single API request (if your data provider supports getMany). Using multiple useOne calls would create multiple separate queries and API requests.