question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Reactive Query Key Change Detection ?

See original GitHub issue

Hi,

I’m probably missing a detail but I can’t use the reactivity of Svelte for queryKey provided to useQuery().

Here is a very basic example of a search box that is not working :

<script>
  import { useQuery } from "@sveltestack/svelte-query";
  import debounce from "debounce";

  let search = "";

  function getTest({ queryKey }) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve(`Response for queryKey ${JSON.stringify(queryKey)}`);
      }, 500);
    });
  }

  const query = useQuery(["test", search], getTest);

  const handleSearch = debounce(event => {
    search = event.target.value;
  }, 200);
</script>

<input type="search" placeholder="Search" on:input={handleSearch}>

See on codesanbox

NOTE: the same logic work perfectly with react-query

Thank for this awesome framwork 💚 …and sorry for my english (Google trad)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7

github_iconTop GitHub Comments

1reaction
amen-souissicommented, May 10, 2021

Hello, you need to update the query options every time the search text is updated.

  $: {
    query.setOptions({ queryKey: ["test", search] });
  }
0reactions
frederikhorscommented, Aug 10, 2021

Another issue is if you try to use:

let queryOptions = {
  queryKey: ["test", search],
  queryFn,
  refetchOnWindowFocus: isVisible,
  enabled: isVisible
};

the query starts two times. It’s a mess!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Change Detection in Angular: Everything You Need to Know
Maximus Koretskyi introduces change detection in Angular, explaining why use cases with immutables work and how change detection strategy ...
Read more >
Effective React Query Keys | TkDodo's blog
The most important part is that keys need to be unique for your queries. If React Query finds an entry for a key...
Read more >
Configuring the Apollo Client cache - Apollo GraphQL Docs
This helps you detect changes to a query's result. ... Each key in the object is the __typename of an interface or union,...
Read more >
Angular reactive forms key changes detection - Stack Overflow
Compare to check form's valuechanges, you can just watch the form's control value's changes by this.companyForm.controls.xxx.valueChanges.
Read more >
Change Detection in Power BI TAIK18 (20-5) Power BI
powerbi #taik18 #changedetectionChange detection is smart way to avoid refresh of all visual in our set scheduled time, it will refresh only ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found