react-query-questions
solid-query-questions
table-questions
virtual-questions
router-questions
react-charts-questions
ranger-questions
vue-query-questions
svelte-query-questions
bling-questions
form-questions
angular-query-questions
start-questions
db-questions
start-showcase
router-showcase
📣-announcements
Best practice around using `useDeferredValue` on mutation status?
idle
to pending
to error
.
From what I can tell, using const deferredStatus = useDeferredValue(mutation.status)
solves this flashing issue perfectly! Unfortunately, it means that I don't get the type narrowing of the original mutation
when trying to use it within the conditional render. Is that just something I have to accept and work around?
I tried wrapping the whole mutation i.e. useDeferredValue(mutation)
, which seemed to work, but it felt wrong to do that given that it's not really a scalar primitive value as suggested by the React docs to use...How to optimistically update onSucess not onMutation?
Recommended approach to type-narrowing `useMutationState`?
useMutationState
. From what I can tell, query uses a wide type because it's pretty difficult to infer the actual mutation state type based on the options for useMutationState
, which is understandable.
What's the recommended approach in this case? Do manual narrowing in the predicate
or select
options?...Error handling with `queryClient.fetchQuery`
useQuery
that used to manage fetching events that occur between two dates. The previous implementation expected external state, so this was no problem before. However, we are migrating to a different library, and it has a very different structure.
It instead expects me to handle (start: Date, end: Date, onSuccess: (events: ...[]) => void
.
Most of the query hook is easily transferable to queryClient.fetchQuery
(select
, success handling, endpoint etc.). However, One thing I lose out on is the query.isError
functionality, which is kind of a shame, because I know that this query can fail due to reasons that the user should know about.
...Pass a generic infiniteQueryOptions object as parameter
API call extremely slow in production but works fine in development
Combining debounced query with `isFetching`
Best way to fetch API data in Next.js with TanStack Query
orm interface for useQuery different hooks synchronization
Question about useSuspenseQuery
UseQuery loading spinner showing right away! :(
Setting state cache on success
How to pass query data to parent component in react?
usequery error typing
NextJS: Prefetching/Hydration overwriting fresher cache data when using streaming SSR with staleTime
`enabled: false` returning cached data
useQuery
and pass in a query object that depends on some data. If that data isn't available or isn't loaded yet, they'll set enabled: false
to disable the query. However, disabling a query only prevents the query from running, and it may still return cached data (see https://tanstack.com/query/latest/docs/framework/react/guides/disabling-queries). People then write the rest of the code expecting data to be undefined, but in prod that data will sometimes happen to be cached by some other part of the app and users will get all of that cached data instead of undefined and the UI will break or behave unexpectedly.
Our solution was to overwrite useQuery
to have the resulting data always be undefined if enabled is false since that's what people on our team expect to happen. Is there any downside to doing this?
I've attached our overwritten useQuery
with what I believe are the correct types (I copy-pasted most of the code from the useQuery
implementation). I don't love having to use useMemo
but it seemed preferable to updating data
directly on the returned object....Tracked properties mutation
useQuery
? Lets assume I am not using isPending from my useMutation, it seems like my component keeps rerendering?Invalidating queryKey with variable doesn't work
5.84.1
):
...Fragment masking with GraphQL code-gen does not work.