createInfiniteScroll from @solid-primitives/pagination with createServerData$ and useRouteData
I'm trying to figure out how to get createInfiniteScroll from @solid-primitives/pagination to work with createServerData$ and useRouteData
I believe createInfiniteScroll expects a fetcher function that returns a Promise<T[]> per the definition https://github.com/solidjs-community/solid-primitives/tree/main/packages/pagination#definition
But I think createServerData$ is like createResource in that it takes an asynchronous fetcher function and returns a signal that is updated with the resulting data when the fetcher completes.
I'm currently trying something like this for createServerData$:
when returning pages() from that I'm getting the errors:
unsupported type
content is not iterable
And trying this for createServerData$ and useRouteData:
when returning pages() from that I'm getting the error:
An error occured while server rendering /pagination:
renderToString timed out
5 Replies
I think this primitive is not ready for solid-start yet.
That's a use case we still need to investigate.
I'm attempting to use it with server$
Seems to be "working"
Except the blinking in the page
For some reason when calling the server$ it's removing all the html in body basically
Adding the server$ call inside a setTimeout and calling setPages seems to be an ugly workaround
I ended up making my own infinite scroll
Hi! I am now also looking into infinite scroll with server fetching, and could use some inspiration 😄, could you share your solution?
Hi @MegaCookie
Sorry for making you wait
With that I've used it like this:
data
is the current data, totalCount
is the total amount of data with the current filter (if there's any filter) in the database
Loading is if it's currently loading data
Load is the method that's called when the user reaches the end and it still has data to load as done by !reachedEnd()
My fetcher is just a server$ function as I use solid-start
Some improvements that can be made:
adding onCleanup
make the loading element customizable
maybe storing getBoundingClientRect on mount instead of on scroll
Hope this helps you!Thanks a lot for your detailed answer 🙏