TanStack

T

TanStack

TanStack is a community of passionate software engineers striving for high-quality, open-source software for web devs

Join

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

quickest-silver
quickest-silver6/30/2024

onSuccess not avaivle in useSuspenseQuery

const { data } = useSuspenseQuery({ queryKey: ["messages", id], queryFn: async () => { const res = await fetchConversations(id); return res;...
rare-sapphire
rare-sapphire6/28/2024

Question about useQuery definition

Hello, Can someone explain to me what "The last successfully resolved data for the query" means? I read it on the docs about useQuery data property: https://tanstack.com/query/v4/docs/framework/react/reference/useQuery#:~:text=The%20last%20successfully%20resolved%20data%20for%20the%20query....
other-emerald
other-emerald6/28/2024

Track data changes

Hi All, What is the bast way to subscribe to updates of my cache in such a way that I only get notified if the data has changed? Doing this from a different place in my app than where I use the useQuery hook. Also, how can I validate structuralSharing is working properly? Is there any quick debug I can use to check this?...
unwilling-turquoise
unwilling-turquoise6/28/2024

infinite loop

Does react query cache the results or error when the api returns an error?. React query custom hook gets called every time when the component is opened if the api is failed previously. Child component also calls the react query hook which I am using to get the data from parent react query call but because the api is failed child also calls api. the code looks like below example. This is causing infinite loop when there is an error customHook....
rival-black
rival-black6/28/2024

Fetching Queries in React Router Actions

I have an action on a route that makes a PUT request and then attempts to fetch a query. The query has keys which are dependent on state variables. Is there a way to update the query by only passing in a constant string instead of needing to pass in all the keys?
other-emerald
other-emerald6/28/2024

React query in typescript strict mode

Hi everyone, I am working in a company where we recently updated typescript in strict mode, so it means the strictNullCheck value will be activated. So now, if I am writing code like this, typescript will raise an error:...
optimistic-gold
optimistic-gold6/28/2024

Possible to persist queries on a per query basis?

I have an expensive query that I want to persist to local storage. It seems I will have to create a persister using createSyncStoragePersister and then add a <Provider> in the react context. But I want it to be saved to localstorage for only a specific query. How can I achieve this?
sensitive-blue
sensitive-blue6/27/2024

Query set default cacheTime

Hello, I'm trying to set the staleTime and cacheTime to infinity in the queryClient default options but the typescript is giving me a warning that I can't set the cacheTime within defualtoptions -> queries (staleTime can be set there fine). Am I missing something? thanks! ```export const queryClient = new QueryClient({...
absent-sapphire
absent-sapphire6/27/2024

v5 codemod does not work with query key variables outside the file

The remove-overloads codemod isn't working for all of my queries, which look like this:
return useQuery(queryKeys.globalApy, handleFetchApy)
return useQuery(queryKeys.globalApy, handleFetchApy)
...
foreign-sapphire
foreign-sapphire6/26/2024

infiniteQueryBehavior :: adding removeEventListener of the signal

Hi, i was studying react-query code and at infiniteQueryBehavior.ts i saw you attach a listener to the signal ```ts const addSignalProperty = (object: unknown) => { Object.defineProperty(object, 'signal', { enumerable: true,...
conscious-sapphire
conscious-sapphire6/26/2024

setQueryData with single signature.

Any interest having setQueryData updated to support a single signature? Would be happy to submit a pull request. I understand that setQueryData doesn't require many overloads, but perhaps there is a desire for conformity with the push towards a single object as an argument....
optimistic-gold
optimistic-gold6/26/2024

`data` becomes undefined / stale data for a second

I am using react-query like so. I am noticing that when I change the value of page via client state, the data returned by the useQuery reverts back to initialData while the fetch happens and then gets populated with the new data. It results in incorrect data being shown for the duration of the fetch (half a second). How can I prevent this?...
No description
foreign-sapphire
foreign-sapphire6/25/2024

Feedback on useQueryStream Hook for Observable Integration with React Query

I’m reaching out for some guidance to validate an idea we’ve been tinkering with—creating a custom hook called useQueryStream to handle Observables with React Query. We know you’ve mentioned before that streaming data flows aren’t officially supported, but we think our situation might be a bit different, and we’d love to get your take on it. We’d really appreciate any feedback you can give us on this approach. Thanks Marco ...
wise-white
wise-white6/25/2024

Specify queryKeyHashFn for queryClient.setQueryData()

It doesn't look like I can set a custom query key serializer with queryClient.setQueryData() https://tanstack.com/query/latest/docs/reference/QueryClient/#queryclientsetquerydata I see that the default options are used, and this is leading me to suggest users of the integration I'm writing to use this global settings. I'm wondering if this is a philosophical thing and I should try to move toward more simply serializeable query keys or if it would make sense to expose this and I should open a PR....
dependent-tan
dependent-tan6/24/2024

how to pass arguments to refetch fuction of useQuerry

I have function in my react native app which gets user latitude and longitude. Executing this function using useEffect. If i get location I want to fetch the data based on location( latitude and longitude ) otherwise want to show fallback component. i disable the query to run automatically by making enable=false. Now how should I pass the location with refetch function to fetch the data....
eastern-cyan
eastern-cyan6/24/2024

Uncaught error on mutation

Hi! I'm trying to catch rejected promise in mutation (onError) . But I get Uncaught error in promise. Unless I wrap await handleCreateGeneral(formData) with try/catch. ...
No description
adverse-sapphire
adverse-sapphire6/23/2024

Is it better to avoid calling `useQuery` many times? (i.e. inside a component that's in a loop)

I know that tanstack query de-dupes the request, but I would like to know if there are any obvious performance problems that may arise from calling the same query multiple times (i.e. n-sized list), as opposed to "lifting it up" to a parent component and passing the query as a prop/context
correct-apricot
correct-apricot6/21/2024

How can I remove the InfiniteData wrapper from the TData type

I am creating an infinteQuery and using a selector to flatten and transform the data. The query works as expected but typescript is complaining because (I believe) the TData type wraps the response type with InfiniteData. Doesn't seem to make a difference whether I leave it to infer or explicitly set the types. Thanks!...
genetic-orange
genetic-orange6/20/2024

can you break down `cancelQueries` to me?

I did not understand this part. I am using optimistic updates but there are no fetches being made during the onMutate callback call while using useMutation. I do not understand what is supposed to happen if I do not use cancelQueries in onMutate like the docs suggest 🤔
No description
optimistic-gold
optimistic-gold6/20/2024

External devtool cannot update component

Hey guys, I'm using the external devtool from this repo: https://github.com/LovesWorking/react-query-external-sync/ But at the moment I have both the debugger and a query on my app, it throw me the error:...