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

fair-rose
fair-rose11/11/2023

Type the api response in useMutation and Usequery

```export interface LoginSuccessRes { access_token: string success: boolean token_type: string }...
generous-apricot
generous-apricot11/10/2023

Type safe way to access queryData using queryKey.

Right now if i want to access query data, i will do something like this queryClient.getQueryData(['GetCountries', { code: 'BR' }]) But 'GetCountries' part is something which is not autosuggested, it is a string value, which can lead to potenial errors. ...
deep-jade
deep-jade11/9/2023

TWO PAGES WITH SAME DATA

I have two pages (analytics and research) But when i go to analytics and later go to research the data of analytics show in research...
wise-white
wise-white11/9/2023

Using keepPreviousData and remove

How should I be using keepPreviousData: true and remove() together? We have a form for user defined search criteria that only searches on button click and also includes a clear button which clears both the form and our grid of results. I followed the example here https://tanstack.com/query/latest/docs/react/guides/disabling-queries and it's mostly working how I want, but because the input values are part of my queryKey the data in the cache is lost as the user types. So I added keepPreviousData: true which then fixes that, but now my clear button doesn't clear the cache. What am I foolishly overlooking? ```tsx...
fascinating-indigo
fascinating-indigo11/9/2023

InvalidateQueries of multiple keys

If I have a query such as this: const todoListQuery = useQuery({ queryKey: ['todosFull', 'todoSpecific'], queryFn: fetchTodoList,...
eager-peach
eager-peach11/9/2023

modifying data fetched by React-Query on the client side

Hi all, I'm new to react-query and I'm building a project and trying to learn along the way. I'm stuck in a requirement and would appreciate the help. Here's an use case: ...
deep-jade
deep-jade11/9/2023

How to handle optimistic update on image

Hello, I've implemented a feature for image uploading, and while it generally functions well, I'm facing a specific issue: 1. A user uploads an image. 2. An optimistic update is performed, and the new image is displayed. 3. The latest user state is refetched upon completion of the upload....
wise-white
wise-white11/9/2023

Property 'isLoading' does not exist on type 'UseMutationResult

I am not sure why I am getting this error shown in the image. I've tried using ChatGPT to help with no success. I am following a very specific video tutorial on YouTube and have followed every step to the T. It works for the instructor on the video using the same code but not me.
No description
fair-rose
fair-rose11/8/2023

Is Suspense example in the docs working correctly?

Hey guys, I'm checking out the Suspense example presented in the docs: https://codesandbox.io/p/sandbox/github/tannerlinsley/react-query/tree/main/examples/react/suspense However, I don't see any fallbacks working in the example. Is there something I don't understand or is there an issue with the mentioned codesandbox? Thanks in advance....
national-gold
national-gold11/8/2023

tanstack router + query + searchParams = keepPreviousData does not work

Hey 👋🏽 , thanks for this great project. I'm using tanstack/router and tanstack/query. The filter + pagination state should be in searchParams. At the query I use keepPreviousData: true, but if a page is not in cache, I get a loading-state. What I'm doing wrong? ```javascript export const participantsRoute = new Route({...
deep-jade
deep-jade11/8/2023

How to set a default `refetchType`

When calling invalidateQueries, I would like refetchType to be set to 'all' by default. I can't find a way to set a default refetchType on the queryClient. Is there another option that will allow me to achieve this default behavior?
harsh-harlequin
harsh-harlequin11/7/2023

mutationFn needs access to a hook

I'm a huge fan of Dominik's post "Leveraging the Query Function Context" (https://tkdodo.eu/blog/leveraging-the-query-function-context) (well, and all of the other ones). I really enjoy defining the query functions separately from the hook as shown in the post. However, when the queryFn or mutationFn depends on another hook, I've had to inline the functions as below: ```export const myCustomHook = () => {...
extended-salmon
extended-salmon11/7/2023

How to detect mutation success event?

I have 2 components ``` // first.tsx const { create } = usePost(); const handleCreate = (payload) => {...
future-harlequin
future-harlequin11/6/2023

useQuery - isLoading state not triggered

I have a Vite + React application. I fetch the todo data based on the page URL id param (example /my-todos/1 , /my-todos/2 etc.) When I switch from the /my-todos/1 to /my-todos/2, the isLoading state stays false and I still see the old todo list for a split second. Currently I fetch data as such: `const { data, isLoading, isError, error } = useQuery({...
wise-white
wise-white11/5/2023

Is calling functions within `queryFn` a bad design?

We use a combination of zod, react-hook-form, and react-query to populate, validate, control, and save our forms. Currently we're doing something like this for populating the schema: ```tsx const { reset } = methods const { data, status } = useQuery({...
passive-yellow
passive-yellow11/5/2023

Pass callbacks for onSuccess, onError and onSettled to each custom hook?

I have a custom hook for each api call my application makes. I wrap the api call with either useQuery or useMutation. The issue is, I need to handle each scenrio that results from that api call. To do this, I am passing callbacks for onSuccess, onError and onSettled to the custom hook. I'm trying to figure out if this is how react-query is intended to be used. Or what the standard / best practice is in this regard? Would it be better to not wrap each of my api calls with the hooks from react-query in my api.ts file? And instead just have the plain api calls. Then whenever I want to call an api endpoint I use the useQuery or useMutation hooks to wrap that api call? That would mean I can pass my callbacks directly to the react-query hook callbacks....
ambitious-aqua
ambitious-aqua11/5/2023

About using useInfiniteQuery

Hello, I'm strugling creating a useInfiniteQuery hook errors is at line 17 with queryFn ```No overload matches this call. Overload 1 of 3, '(options: UndefinedInitialDataInfiniteOptions<Post[], Error, InfiniteData<Post[], unknown>, QueryKey, unknown>, queryClient?: QueryClient | undefined): UseInfiniteQueryResult<...>', gave the following error....
jolly-crimson
jolly-crimson11/4/2023

Cancel useInfiniteQuery pending API's

Hi, I have a useInfiniteQuery search API that takes a a user entered search param and returns some results. I want to cancel any ongoing API calls if the user enters a new search param value. Any ideas on how to do this?...
vicious-gold
vicious-gold11/4/2023

Is it possible to automatically invalidate suspense query before fetching?

I have a form with auto-save. If I leave after making changes and navigate back, I receive the stale data first despite the query being stale and then fresh data. I would like to receive only the updated data and have the regular suspense behavior. I populate the state from the query data initially and do not want to synchronize it with query responses. I could invalidate it myself which is tedious and if the changes would happen outside of the client there would be no way to invalidate the quer...