Code Monkey home page Code Monkey logo

Comments (3)

fivecar avatar fivecar commented on September 26, 2024

Upon a little more digging, the core query object in react-query ~ seems ~ to return the same promise. Specifically, in query.fetch source:

  fetch(
    options?: QueryOptions<TQueryFnData, TError, TData>,
    fetchOptions?: FetchOptions
  ): Promise<TData> {
    if (this.state.isFetching)
      if (this.state.dataUpdatedAt && fetchOptions?.cancelRefetch) {
        // Silently cancel current fetch if the user wants to cancel refetches
        this.cancel({ silent: true })
      } else if (this.promise) {
        // Return current promise if we are already fetching
        return this.promise
      }
  ...

And query objects are cached in a queryMap that's used by each queryClient.

The big caveat is that I've researched this all of 5 mins, while you obviously know a lot more about this whole thing (to the point where you created a package specifically to solve this problem), so I apologize beforehand for the great likelihood that I'm misunderstanding the whole thing.

from memoized-node-fetch.

chrispanag avatar chrispanag commented on September 26, 2024

Hello @fivecar! Thanks for the interest and the nice words!

When I created this package, react-query was somewhere around version 2.19.0. Back then, after some people asked me, I checked if react-query does promise caching, and as far as I digged into it, I didn't find any evidence of promise caching.

It seems like this feature was added with v3 around 10 months ago.

Screenshot 2021-09-30 at 12 49 58

Some more facts:

  1. When I created this package, I mostly intended to use it in nodejs, and not in the browser, so I didn't even consider checking any existing packages for the browser.
  2. Well, react-query does 100,000 more things (which is generally good) but some times you don't need all of those, so if that's the case, I would choose my package.

from memoized-node-fetch.

fivecar avatar fivecar commented on September 26, 2024

Awesome - super-helpful, @chrispanag ! I've created #8 as a result of your thorough explanation, which I really appreciate!

Thanks again for all the time and effort you put into this. Love it!

from memoized-node-fetch.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.