xenial-black
xenial-black3mo ago

multiple uselist delay

I have multiple calls of uselist on a page, I want to make them called one by one so the page is less heavy on load. how do I do it?
17 Replies
kapa.ai
kapa.ai3mo ago
Hi @SetiZ. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- I'm sorry, but the knowledge sources do not contain explicit information or recommended patterns for making multiple useList calls execute sequentially (one after another) instead of in parallel. By default, Refine's useList hook (built on TanStack Query) triggers all data fetching hooks in parallel when rendered, and there is no documented built-in mechanism to queue or delay these calls within Refine itself. If you need this behavior, you would likely need to implement custom logic to control when each useList is rendered or triggered, but the knowledge sources do not provide an example or official guidance for this scenario. If you have further questions or need help with other aspects of Refine, feel free to ask! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3mo ago
@kapa.ai maybe using Promises? i can do it with that?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources do not provide any explicit guidance or examples for using Promises to control the execution order of multiple useList calls in Refine. While Promises are a common JavaScript tool for managing asynchronous operations and sequencing them (as discussed in general programming best practices)Best Practices and Patterns, there is no documentation or example showing how to integrate this approach with Refine's useList hook. By default, useList is designed to fetch data as soon as the component renders, and there is no built-in option to delay or chain these calls using Promises within Refine's documented API. If you need to strictly control the order of data fetching, you would need to implement custom logic outside of what is described in the knowledge sources. I'm sorry I can't provide a more concrete solution based on the available documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3mo ago
@kapa.ai what about uselist auto pagination? how can i do it?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources do not mention an "auto pagination" feature for useList in Refine. Pagination with useList is handled manually by passing the pagination property, where you control the current page and page size. You can update these values (e.g., with buttons or UI controls) to fetch the next or previous page, but there is no built-in "auto" or infinite scroll pagination for useList documented in the sources. If you are looking for automatic loading of more data as the user scrolls (infinite scroll), Refine provides the useInfiniteList hook, which is designed for this purpose. useInfiniteList allows you to fetch additional pages of data as needed, typically triggered by a "Load More" button or scroll event, and is better suited for auto/infinite pagination scenarios useInfiniteList documentation useInfiniteList Example. For useList, you need to manually manage pagination state and trigger data fetching for each page useList Pagination. There is no mention of an "auto" mode for pagination in useList in the provided documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3mo ago
@kapa.ai can we do useinfinitelist and trigger the load automatically?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can use useInfiniteList and trigger loading the next page automatically. While the default usage in the documentation shows loading more data with a "Load More" button, you can programmatically call the fetchNextPage function provided by useInfiniteList to load additional pages whenever you want (for example, in response to a scroll event or any other condition). Here’s how you might use it:
const {
data,
isLoading,
hasNextPage,
fetchNextPage,
isFetchingNextPage,
} = useInfiniteList({
resource: "categories",
pagination: { pageSize: 4 },
});

// You can call fetchNextPage() automatically based on your logic
// For example, in a scroll event handler or useEffect
const {
data,
isLoading,
hasNextPage,
fetchNextPage,
isFetchingNextPage,
} = useInfiniteList({
resource: "categories",
pagination: { pageSize: 4 },
});

// You can call fetchNextPage() automatically based on your logic
// For example, in a scroll event handler or useEffect
The documentation shows fetchNextPage being called on a button click, but you are free to call it in any event handler or effect to achieve automatic loading useInfiniteList documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3mo ago
@kapa.ai can I use it with useEffect and load the next page?
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can use useInfiniteList and trigger loading the next page by calling fetchNextPage inside a useEffect or any other event handler. The documentation shows fetchNextPage being called on a button click, but it is a function you can invoke programmatically whenever you need to load more data. This allows you to implement automatic loading logic, such as triggering on scroll or within a useEffect, as needed for your application useInfiniteList documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
xenial-black
xenial-blackOP3mo ago
@kapa.ai show me the useeffect code example
kapa.ai
kapa.ai3mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm sorry, but the knowledge sources do not provide an explicit example of using useEffect with useInfiniteList to automatically load the next page. The documentation only shows fetchNextPage being called from a button click or similar user interaction useInfiniteList documentation. If you need an official example or best practice for triggering fetchNextPage inside useEffect, it is not covered in the provided sources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai3mo ago
<@267689263246606336> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?