Skip to content

fix: update queryHash when queryKey is updated using updateOptions#55

Merged
SomaticIT merged 2 commits intoSvelteStack:mainfrom
SomaticIT:@fix/update-query-hash
Nov 11, 2021
Merged

fix: update queryHash when queryKey is updated using updateOptions#55
SomaticIT merged 2 commits intoSvelteStack:mainfrom
SomaticIT:@fix/update-query-hash

Conversation

@SomaticIT
Copy link
Collaborator

@SomaticIT SomaticIT commented Sep 4, 2021

Hi,

Description

I noticed that when queryKey is updated using the new updateOptions method, the query is not refetched.
This happens because the previous queryHash is not updated.

In this PR, I detect if queryKey is updated and I manually update the queryHash.

Reproduction

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

  const query = useQuery(["entities", { search: ""  }], fetchEntities);

  function onSearch(e) {
    query.updateOptions({ queryKey: ["entities", { search: e.target.value }] });
  }
</script>

<input type="text" on:change={onSearch} />

{#if $query.isLoading}
  Loading...
{:else if $query.data}
  {#each $query.data as entity (entity.id)}
    <p>{entity.name}</p>
  {/each}
{/if}

@SomaticIT
Copy link
Collaborator Author

@amen-souissi, any news on this?

@SomaticIT SomaticIT merged commit 2d5de76 into SvelteStack:main Nov 11, 2021
@SomaticIT SomaticIT deleted the @fix/update-query-hash branch November 11, 2021 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant