TanStackT
TanStack2y ago
7 replies
brilliant-lime

How to refetch if queryKey is unchanged

let [foo, setFoo] = useLocalStorage('myfoo')
let [result, setResult] = useLocalStorage('myresult')

useQuery({
  queryKey: [foo],
  initialData: { result },
  refetchOnMount: false,
  enabled: Boolean(foo),
  queryFn: async() => {
    const res = await fetch(foo)
    let result = await res.json()
    setResult(result)
    return { result }
  }
})

function onSubmit(nextFoo: string) {
  setFoo(nextFoo)
}


hi everyone, i am trying to get the above code to work, but if the user submits the form again with the same value of "foo" i want to refetch. currently it only refetches when foo is changes between form submissions
Was this page helpful?