useQuery error response is always stale? #5411
-
Hi, I've had a look through the discussions here and can't find anything specific to this, so hopefully someone here can shed some light on my problem. The sandbox linked below illustrates my problem: I have a basic query that rejects the promise with an error if the response is not ok. In the test, I'm returning a I would imagine that this would set Link to sandbox: https://codesandbox.io/p/sandbox/exciting-heyrovsky-f5qo6y?file=%2Fsrc%2Ftest-hook.test.jsx%3A18%2C7 Any help would be greatly appreciated. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
it's stale because queries that have no data are always considered stale. The problem in your situation is automatic property tracking. We only track properties that you are using, which is a render optimization. In your example, you're only using the You can set But generally: This is one of the reasons why I'm not a fan of testing hooks in isolation. Rather test the component that is using the hook and you will test what your users are seeing. here's a working fork of your sandbox (I've set it to |
Beta Was this translation helpful? Give feedback.
it's stale because queries that have no data are always considered stale.
The problem in your situation is automatic property tracking. We only track properties that you are using, which is a render optimization. In your example, you're only using the
refetch
value returned fromuseQuery
and nothing else, so your hook doesn't re-render when new data / error comes in.You can set
notifyOnChangeProps: 'all'
for your hook (or for the queryClient that you use for testing) to work around this.But generally: This is one of the reasons why I'm not a fan of testing hooks in isolation. Rather test the component that is using the hook and you will test what your users are seeing.
here's a working …