Append data on useFetch on page change instead reload
Hi I would like to keep my data of previewed pages and append new data of the existing cached or stop if no more pages.
Should I do separate useState or try it inside useFetch, i do not care about hard reloaded data,
galleryData
is for infinite gallery variable
4 Replies
Hi @HardWare. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
To append data on
useFetch
when the page changes instead of reloading, you can modify your existing code to achieve this. Here's how you can approach it:
1. Use a separate useState
to store the accumulated data:
2. Modify your useFetch
call to append the new data to the accumulated data:
This approach will keep appending new data to the accumulatedData
state on each page change, while still maintaining the caching behavior you've implemented.
To stop fetching when there are no more pages, you can add a condition in your component that increments the page
value:
This way, you'll only load more data if there are more pages available.
Remember that this approach will keep accumulating data in memory. If you're dealing with a large amount of data, you might want to consider implementing a strategy to limit the amount of data stored, such as keeping only the last N pages or implementing virtual scrolling.
Docs > Api > Composables > useFetch provides more information on the useFetch
composable and its options.
----------------------
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
----------------------<@358326054357565442> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
use pinia
I had consider it but I think thats to much powerhouse just for gallery infinite scroll