Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to implement something like useInfiniteQuery from @tanstack/query ? #38

Open
hemandev opened this issue Apr 21, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@hemandev
Copy link
Contributor

Hi,
First of all, let me say this is a great library, and I'm loving it so far.

I am using query along with nanostores to build a framework-agnostic library, which I can then use to build components for each framework. All the business logic and reactivity stay in this "core" library.

TLDR;
Is it possible to do something like useInfiniteQuery in @tanstack/query?
https://tanstack.com/query/v5/docs/framework/react/reference/useInfiniteQuery
I want to build the whole infinite scroll data store inside VanillaJS so that I can reuse the same store in React, Vue, Angular etc...

@dkzlv
Copy link
Member

dkzlv commented Apr 22, 2024

@hemandev It sure is possible, yeah. If I were to solve this issue in a component library world, this is the way I'd go:

  1. define Page component that accepts all arguments required for fetching a page (it can be cursor, page or whatever);
  2. implement a factory function that accepts those arguments and returns a fetcher store with these arguments pre-defined;
  3. call this factory function in Page component, and pass props as arguments. Memoize the result (mamoization can be soft, without hard guarantees: nanoquery has its own data cache layer that's component/tree agnostic);
  4. subscribe to this store;
  5. render new Page component whenever user approaches the bottom of current page.

Basically, this thing.

But, as you can see, it's not something that looks particularly like useInfiniteQuery, and there's no helpers that's part of the core yet, so it may require some custom code wrapping nanoquery. That's one of the features I'd like to implement some day, but right now it's not there yet.

@dkzlv dkzlv added the enhancement New feature or request label Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants