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

generous-apricot
generous-apricot2/1/2024

Trouble with navigation after useMutation

Hi, I have a useMutation which gets called on an onSubmit to my login form. I call an endpoint on my server which returns a cookie with JWT token. All of this works correctly, however after I get the cookie i try to navigate to the /dashboard. It seems that if i do this right away the navigation does not work correctly but if i sleep for even a 100 ms it works (I have a before loader on the dashboard page that checks for the cookie being present). I'm guessing the cookies arent being set right away, and that a 100ms delay is enough for it to work but I'm not sure. I would really appreciate any help this is my first time working with TanStack. ``` const mutation = useMutation({...
afraid-scarlet
afraid-scarlet1/31/2024

What is the best way to paginate my queries (limit/offset on db) using tanstack table and query

I have a Node aplication on the back-end doing raw SQL and a React appliction on the front-end using tanstack table and tanstack query. if anyone has some tips or code that would help it would be apreciated
overseas-lavender
overseas-lavender1/31/2024

Trigger useQueries fnc in onSuccess of other func, but queryOptions fnc has diff queryKey

` export const useFetchDataScreen = (id:number):any => {
const assignDataFn = (id: number) => { return queryOptions({ queryKey: ['assignKey',id],...
conscious-sapphire
conscious-sapphire1/31/2024

can use only 2 args on useQuery()

Hi I can’t use more than 2 arguments when invoking useQuery with options (keepPreviousData) Error : no overload match this call...
harsh-harlequin
harsh-harlequin1/30/2024

How to know if a state has changed from another component using useEffect

Details of my question are provided below: https://stackoverflow.com/questions/77903315/how-to-know-if-the-state-in-react-query-has-changed-from-another-component-using Note that it's not the same case of mine, but it's something very relative....
other-emerald
other-emerald1/30/2024

How to get cache update in another component when data has been updated somewhere else?

Using tanstack/svelte-query. It returns undefined but the data in the cache is updated after fetching. ```js...
correct-apricot
correct-apricot1/30/2024

Are errors cached in react-query?

Say i have a query in my component. and for some reason it returns an error. i see that if i travel back to that component, a request is not remade, even though my staleTime is set to 0. ...
secure-lavender
secure-lavender1/30/2024

invalidateQueries

Why is the incorrect way of invalidating working and the what I believe is the correct way not? ```const result = useQuery({ queryKey: [WORKOUT_CACHE_KEY, ['/set'], id], queryFn: () => getSets(id),...
stormy-gold
stormy-gold1/30/2024

Showing a message if a request is taking a long time

Hello, I'm trying to do something like show a message if a request (in this case, a mutation), is taking a long time. This is what I have so far: ```tsx export const useExampleHook = () => {...
national-gold
national-gold1/29/2024

Tip on improving data fetching of google map markers

Hey, for a customer I am creating a post pickup point map, using the google maps api, geocoding and autocomplete. For the markers I fetch new markers for the items that are in the viewport, and I do this every-time when the center of the map changes. (it is debounced, so not excessive) I have a useQuery hook, that stores the postalcode for each search as a cache key, this is a limitation of the API we are using, it does not accept bounds or latlng values. Since I fetch the data for every postalcode seperatly, the other markers are not longer visible when zooming out, which is the way it should work since those cache keys are no longer active. ...
robust-apricot
robust-apricot1/29/2024

Why no TS useQuery type?

Hello, In the useQuery docs, there is a pretty explicit return data object definition (data, dataUpdatedAt, error, errorUpdatedAt, failureCount, etc...). Why is it not available to define in my code? (I keep reading complicated stuff about generics)......
robust-apricot
robust-apricot1/28/2024

Does react-query conflict with server components in Next.js?

From the Next.js docs:
Next.js has a built-in Data Cache that persists the result of data fetches across incoming server requests and deployments. This is possible because Next.js extends the native fetch API to allow each request on the server to set its own persistent caching semantics.
If I just make the react-query fetcher use native fetch (not axios or something) it shouldn't conflict right? ...
national-gold
national-gold1/28/2024

Default Mutation Function best practices and Typescript

I've set up a default query function per the guide in the docs, but there's no guide on a default mutation function. I'd like to set on up so I don't have to get the auth token in each component, etc. Can I just do the following: ```javascript type MyMutationFunctionProps = { apiPath: string...
adverse-sapphire
adverse-sapphire1/28/2024

Remix hydration errors

I'm getting hydration errors using react-query with remix. Seems the server is caching initialData on subsequentRequests. This repro shows that after hydrating a page with a query populated with initialData from the server, remix will blow up when refreshing on another page using the same query without that same initialData. This is because the server has the original initialData and so is rendered with the cached data, but the client does not have access to that initialData and renders isLoading state. https://stackblitz.com/edit/remix-run-remix-zjutjv?file=app%2Fcomponents%2Fcomponent.tsx...
rare-sapphire
rare-sapphire1/27/2024

pnpm workspaces, @tanstack/query-core not resolved by @tanstack/react-query

I'm trying to switch over to pnpm in my monorepo but am getting the following Typescript error when using React Query: Module '"@tanstack/react-query"' has no exported member 'QueryKey'. When digging into what is exported, I noticed that react-query isn't detecting the core package - where I'd think these types are exported from. ...
No description
other-emerald
other-emerald1/26/2024

useMutation - updating a single entry in onMutate

I am trying to follow the tutorial on tanstack for doing optimistic updates. I cannot make their example work in my app for updating a single entry in the onMutate function. I am following the guide here: https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates for "Updating a single todo".
united-yellow
united-yellow1/26/2024

Mutate send response

Not sure if im being stupid or what, is the best way to pass back the response using useState or is there a easier way for me to access the response. Also any advice to clean up the code is appreciated 🙂 ``` import { useMutation } from '@tanstack/react-query'; import { Endpoints } from '@/config';...
xenial-black
xenial-black1/26/2024

How to run dynamic Query in Tanstack Query?

0 I've been having a rough time understanding tanstack/query. I'm trying to fetch data using tanstack. What I'm trying to get is store the data in my state, and then when I press the button, it will pass to my URL and then it will call the button....
adverse-sapphire
adverse-sapphire1/26/2024

handling updates to optimistically rendered items that haven't resolved yet

When a user adds a todo, I optimistically render it. However, it won't have an 'id' until the mutation actually resolves. If the user tries to edit the todo before it has an id, it causes problems. The easy but bad UX solution would be to disable interaction until the mutation resolves. I think it would be better if there was a way to queue the next mutation and have it wait on the first one resolving. I feel like you could do something with useIsFetchching here. Would appreciate some ideas!...
xenophobic-harlequin
xenophobic-harlequin1/25/2024

mutationOptions helper

Hi there! I've been working on refactoring some of my codebase's react-query usage (with inspiration from https://tkdodo.eu/blog/the-query-options-api). I see there is a queryOptions helper, which can be used to build QueryOptions objects, and I've gotten through refactoring all of my queries. Is there such a thing for useMutation? Even though my function is returning a type that satisfies UseMutationOptions, typescript seems to not like it. Any suggestions? Thanks...
No description