fascinating-indigo•6d ago
what is the difference between result.data and query.data
In 5.0 the useList, useCustom etc return a result and a query object. But data exists in both?
2 Replies
Hi @Todilo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
In Refine v5, hooks like useList and useCustom return two main objects: result and query. The key difference is:
- result.data: This is the normalized data returned by the hook, specifically designed for your application's use. For example, in useList, result.data contains the array of records you requested (e.g., a list of products). This is the value you should use in your UI components.
- query.data: This is the raw data returned by the underlying TanStack Query's useQuery. It may include additional metadata or be in a less convenient shape, depending on your dataProvider and query configuration.
The documentation and migration guides emphasize that you should use result.data for accessing your actual data, as it is consistent and type-safe across all hooks. The query object is primarily for query state (isLoading, isError, refetch, etc.), while result is for the actual data and total count:
Use data from result, not from query, for your application logic. This change was made in v5 to unify and clarify the API, making it more predictable and easier to use across all hooks Data & Mutation Hooks: Return Type Breaking Changes.
If you need to access the raw TanStack Query result (for advanced use cases), you can look at query.data, but for most scenarios, stick with result.data.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------
<@207945811592478720> Kapa.ai is still learning and improving, please let me know how I did by reacting below.