I don't understand how useTable works
What action does this hook call? Does it even use my dataProvider? If not, what hook can I use that actually uses my dataProvider without making it a hassle to deal with pagination?
2 Replies
Hi @chrystiansilva. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
The
useTable
hook in Refine is designed to fetch data according to the sorter, filter, and pagination states. It uses the useList
hook under the hood for fetching the data. It's designed to be headless, meaning it expects you to handle the UI. However, Refine offers seamless integration with several popular UI libraries, simplifying the use of their table components (source (https://refine.dev/docs/data/hooks/use-table/)).
When you use the useTable
hook, it calls the getList
method from your dataProvider
under the hood. The dataProvider
is a property that allows communication with the API. All the data fetching and mutations are done through this property (source (https://refine.dev/blog/build-internal-tools-using-low-code-with-refine#communicate-with-the-api)).
Here's an example of how you might use the useTable
hook:
(source (https://refine.dev/docs/guides-concepts/tables#basic-usage))
In this example, useTable
is used to fetch data from the "products" resource with a specified pagination state. The fetched data is then stored in the posts
variable.
If you want to use a hook that uses your dataProvider
and handles pagination, you can use the useList
hook. It fetches data according to the pagination, sorter, and filter states, and it uses your dataProvider
to do so (source (https://refine.dev/docs/data/hooks/use-list/)).
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------stormy-goldOP•12mo ago
"When you use the useTable hook, it calls the getList method from your dataProvider under the hood."
I'm not sure about this. I'm running 4.46.1, here's my mocked data provider:
When accessing my page, the "@ getList" console.log is not seen anywhere. Here's the code to my page:
Changing the logic in my dataProvider's getList method to always return an empty array did in fact make the table show no records, but I was very confused as to why I couldn't see the logs in my console.