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

foreign-sapphire
foreign-sapphire7/5/2024

How to do the Optmistic Update?

I'm trying to do the optmistic update . In my queryKey I'm using a page state, should I use it in getQueryData as well? Another thing, in my response I get an object with the pagination and an array with the data, how can I do the optimistic update under these conditions?
mute-gold
mute-gold7/5/2024

How would I manage a streamed response from the server?

I am effectively making a chatbot. If you were to imagine it in "plain JS", it might look like this: ```typescript async function createStream(reader: ReadableStreamDefaultReader<string>): AsyncGenerator<string, undefined, undefined> { const { value, done } = await reader.read(); if (done) return;...
frail-apricot
frail-apricot7/5/2024

Debounced Autosave

Hi everyone, I have an app where I’m trying to implement an autosave. Each time a user enters input into one of many input fields, I want to update the data across the application. However, I want to debounce the actual mutation and proceeding cache invalidation so it only happens five seconds after the data has stopped changing. What is the best way to go about this?...
dependent-tan
dependent-tan7/5/2024

How to use `useSuspenseQuery` to ensure data is always there?

Hey all. I'm working on an app where basically each screen is bound to be accessed if the user is in an account. I want to develop a hook that will provide the account data and avoid doing undefined checks. Right now, I grad the account id from the url, pass it to a query where and use enabled to decide if the query should be called. It is called each time but the undefined checks are annoying. Another approach is to retun null early if (!accountId), which is also annoying. Here is what I have so far: ```tsx import { useSearchParams } from 'react-router-dom';...
equal-jade
equal-jade7/4/2024

I hava a question for maintainer.

Hi, I have a question for a really pure question for maintainer. Why did you use the term 'query' in your library name? @TkDodo šŸ”® @Tanner Linsley
conscious-sapphire
conscious-sapphire7/3/2024

StrictNullCheck and dependant queries

Hi, me again ! I am working with typescript strict mode, and I am not sure what would be an elegant solution to handle dependant queries. I have typesafe abstracted queries that require data to be set: - useGetDetails...
conscious-sapphire
conscious-sapphire7/3/2024

How to type queries without inference?

How can I remove as const from this and add real types?
No description
deep-jade
deep-jade7/3/2024

cancelQueries does not seem to cancel trpc fetches

``` try { queryClient.cancelQueries({ exact: false, stale: false, fetchStatus: 'fetching'}); } catch (error) { console.log("Cancelled the queries");...
sunny-green
sunny-green7/2/2024

React native - mutations are paused, but are not in the queryClient paused mutations so don't resume

In summary, I have a use case where I manually allow the user to trigger online/offline status. When I go back online though, the mutations do not seem to resume at all. Not sure what I am doing wrong:




...
flat-fuchsia
flat-fuchsia7/2/2024

setQueryData changes in v5?

I'm upgrading my project from v4 to v5 of react query today and have just a couple typescript errors with some calls to setQueryData:
Argument of type 'Decimal' is not assignable to parameter of type 'Updater<void | undefined, void | undefined>'
Argument of type 'Decimal' is not assignable to parameter of type 'Updater<void | undefined, void | undefined>'
...
vicious-gold
vicious-gold7/2/2024

How to use react query data in another component without moving state up?

I am using nextjs app router + typescript + react-query. Currently my app has an input that asks a user for a url, which is then used to fetch a list of github issues. Here are the simplified versions of the files: url-form.tsx: ```typescript "use client";...
itchy-amethyst
itchy-amethyst7/2/2024

isLoading vs isPending

When should i use isLoading and when should i use isPending?
extended-yellow
extended-yellow7/2/2024

How to setQueryState to error

I'm using WebSockets to push new data to the client and calling QueryClient.setQueryState with the new data to update useQuery hooks for that query all over my app. But what about when the state I want to update with is an error? How do I inform the QueryClient of an error?...
stormy-gold
stormy-gold7/1/2024

How to organize react query project

I have question about organizing react query, currently I have folder services with folders like users, posts, and there is file for server data fetching functions called api.ts, and another file for queries and mutations (queriesAndMutations.ts) would it be better solution to rename api.ts for example for posts, to postService, make it file that exports postService = new class postService, and there store all api calls as methods...
provincial-silver
provincial-silver7/1/2024

page re-renders 100s of times when using with Wagmi (and SWR)

Just asking here, in hopes someone has came across this. We are using a stack, which is roughly composed of * next.js (pages)...
other-emerald
other-emerald7/1/2024

How to access mutationState in v4? What is the pattern to work on project with many mutations?

I have a project where my entities have many states. State is changed by post requests. I have many post requests, that return current state or error of entity. I would like to have access to the data of post request in another component. So now i just setQueryData in onSuccess and onError. Is this right?...
fair-rose
fair-rose6/30/2024

useInfiniteQuery cache for useQuery

Best explained by example website.com/todos/ Show all todos with useInfiniteQuery , results are stored in cache ```ts...
evident-indigo
evident-indigo6/30/2024

onSuccess not avaivle in useSuspenseQuery

const { data } = useSuspenseQuery({ queryKey: ["messages", id], queryFn: async () => { const res = await fetchConversations(id); return res;...
correct-apricot
correct-apricot6/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....
quickest-silver
quickest-silver6/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?...