Replies: 2 comments 8 replies
-
it's not allowed to return There should also be an error in the console in dev mode: query/packages/query-core/src/query.ts Lines 475 to 477 in 35539bf |
Beta Was this translation helpful? Give feedback.
-
I actually agree here that it seems odd that undefined has a reserved purpose for signaling internal cache state changes (or non-changes in this case), which means that it can no longer be used to represent the value of the cached item itself. My use case was to set the cache value to undefined to represent that the value is in fact no longer defined (in our case, it was deleted). We can and likely will use null (or an empty obj) instead, but these other falsy vals have their own meaning too, so I'm wondering if there's a more graceful solution here longer term. |
Beta Was this translation helpful? Give feedback.
-
Hello there 👋
When using a query that return
undefined
, the cacheTime and refetch options are not taken into account. It could happen that a call to a server return an undefined value, and we don't want to re-request to prevent too much server-side computations.We can also want to use useQuery as a better useEffect, that should return nothing.
The workaround is to return something, but it's not really explicit for developer, and is not good for maintainability as not every developer knows about that tricky solution 😭
If it's to know if a cache exists for that query, react-query should use:
For:
instead of
That's a DX issue, so what do you think about that ?
Thanks 🙌
Beta Was this translation helpful? Give feedback.
All reactions