I want to implement an infinite scroll in a component, but my back-end doesn't have a "current" endpoint which means that the actual version of infiniteQuery is out of the question (as far as I understand).
In my component I created a query using a stateful variable as a queryKey parameter:
useQuery([`posts_paginated`, { page }] {
// request to http://.../posts?_sort=createdAt&_order=desc&_page=${page}&_limit=10
}
My issue is that modifying the query key creates a new query instance triggering the isLoading boolean in the response object and the rendering value of the component depends an that:
return (IsLoading) ? <LoadingComponent /> : <ViewComponent />
This means that when the page variable is set, the ViewComponent is unmounted with the result that I lose the current position of the scrolling bar.
I tried invalidating the query instead so that only isFetching would trigger, but I think that since the callback closure for the query is already set the parameters values can't be changed that way (I couldn't get it to run with anything but the initial values).
I could stop rendering contitionally with isLoading or I could start managing my scroll bar position explicitely in some state, but I'm wondering if there is an obvious way to achieve what I need just using react-query.