GithubHelp home page GithubHelp logo

Comments (10)

NetanelBasal avatar NetanelBasal commented on May 22, 2024

It's because it's cached.

from query.

seanbruce avatar seanbruce commented on May 22, 2024

With react-query, when new component that use useQuery mounted, the data cached in queryClient with the same key in useQuery will returned for rendering and at the time refetching new data at the background. from the users pecpective, they saw cached data immediately and will see content update if the refetching return different data. The cache behavior is the same for angular query, but not the refetching behavior.

from query.

NetanelBasal avatar NetanelBasal commented on May 22, 2024

In your react application, could you try setting in the global query config the staleTime to Infinity and tell me if it still works the same?

from query.

seanbruce avatar seanbruce commented on May 22, 2024

After setting staleTime to Infinity, the query won't refetch on re-mounted. so, In my Angular application, after setting the stateTime of useQuery to 0, it will refetch automatically when component re-mounted.

 getTodos() {
    return this.#useQuery(
      ['todos', 'list'],
      () => {
        return getTodos();
      },
      { staleTime: 0 }
    );
  }

In according to the reference of useQuery in the docs, staleTime is default to 0. I wondered why the default is different in angular query, just curious.

from query.

NetanelBasal avatar NetanelBasal commented on May 22, 2024

It's just a hunch based on my usage. But now I wonder if it's better to leave the default as react-query to avoid future discussions like this.

from query.

NetanelBasal avatar NetanelBasal commented on May 22, 2024

Now I also wonder if it's the same issue here - #56

Can you check it with staleTime set to 0, please?

from query.

seanbruce avatar seanbruce commented on May 22, 2024

Sure, and after setting options like this

getTodos() {
    return this.#useQuery(
      ['todos', 'list'],
      () => {
        return getTodos();
      },
      { staleTime: 0, refetchOnWindowFocus: true }
    );
  }

The query still won't refrech on windows focus. no matter refetchOnWindowFocus set to true or "always".

from query.

NetanelBasal avatar NetanelBasal commented on May 22, 2024

Thanks. I'll remove the default staleTime that we set.

from query.

seanbruce avatar seanbruce commented on May 22, 2024

@NetanelBasal Thanks for your response. I'll close this issue.

from query.

NetanelBasal avatar NetanelBasal commented on May 22, 2024

Done

from query.

Related Issues (20)

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.