387 questions
Best practices
0
votes
0
replies
26
views
TanStack Query in React Native - A Rick & Morty server-side filtering question (interactive example inside)
I prepared an interactive/editable single file expo-snack example that you can run in the browser (or simply download the expo go app on your phone, scan the QR code and you're ready to go)
I have a ...
1
vote
1
answer
98
views
Infinite scrolling using nextjs16 and useInfiniteQuery (Tanstack)
I am trying to implement infinite scrolling in a React (Next.js) application using Tanstack Query (useInfiniteQuery) and the IntersectionObserver API.
I understand the basic idea of fetching paginated ...
1
vote
1
answer
46
views
ViteJS - Returning a promise in a field of a React Hook
To migrate from React-Query V3 to V5 (Tanstack/React-Query), I have to change my usage of the lib because of one breaking change: undefined isn't an allowed return value for queryFn anymore. That's ...
1
vote
1
answer
1k
views
What is the use case for TanStack Start useServerFn hook
I am currently exploring TanStack Start (with React).
At What are Server Functions? page we have example of server function that can be used with useQuery (from TanStack Query, to fetch data from ...
0
votes
0
answers
51
views
Tanstack Query: Multiple chained POST calls with rollback
I have an issue where I need to make 3 chained POST calls using Tanstack Query.
POST with query 1
If query 1 fails, stop
If query 1 succeeds, make POST query 2
If query 2 fails, rollback query 1
If ...
0
votes
2
answers
186
views
How can I have a delay until useQuery/refetch have returned the data
I am developping an iOs/Android App with React Native.
I am using useQuery (TanStack Query v5) to send the username and an hashed password to my database and it return the user ID if the email/...
0
votes
0
answers
66
views
Can a Tanstack query function return the results of another query function?
We're in an awkward situation needing to consume an API endpoint that is not built correctly. It returns pages of (unsortable) records without revealing beforehand how many pages there are in total.
...
0
votes
1
answer
276
views
Can Tanstack/React Query handle dynamic parallel queries that are computed based on earlier queries?
I see that Tanstack Query supports parallel queries in a certain way that is dynamic, per this page: https://tanstack.com/query/latest/docs/framework/react/guides/parallel-queries#:~:text=each%...
0
votes
0
answers
27
views
React Query Cache Not Updating After File Upload - Manual Invalidation Required
Problem
After uploading new trade files through an "Upload New File" dialog, the trade reconciliation table shows stale data from the previous upload instead of the updated data. The table ...
0
votes
1
answer
102
views
problem with Hooks and Components: Error Invalid hook
I’m building a react native app using expo and I created a component called FlightList.tsx that fetches flight data using a custom hook useFlightList.tsx (which internally uses React Query’s useQuery)....
2
votes
0
answers
83
views
TanStack query local storage full
We are using TanStack query (Vue) for storing a lot of states in the local storage.
But what happens if the local storage is full?
Will it just discard the oldest query if we store a new query?
0
votes
1
answer
219
views
TanStack Query useMutation is not return isSuccess true after success response
I have an authentication system. calling Api's using tanstack query.
When logging in, signing up, and verifying email using the link, everything works fine. However, when I check the mutation's ...
0
votes
1
answer
220
views
RefetchInterval, and QueryKey Changing, will this cause two network requests?
Really need some help understanding the nuances and effects of how refetchInterval, and queryKeys interact with each other.
Currently, I have a UI that is stuck on loading state. I suspect it is ...
0
votes
2
answers
65
views
How to make react-query wait till input data used in request is resolved with other API call?
I am using tanstack-query and have dependent queries to do:
const { resourceId } = useGetResourceId(); // resourceId: number | null
const { data, loading, error } = useGetResourceData(resourceId);
...
2
votes
1
answer
109
views
how to manage jotai atoms effectively to prevent circular dependency when using joati on frontend, with react-query?
I am trying to create a sort of complex react/jotai game with a next.js frontend server router connected to an express/node.js backend server.
I keep getting circular dependency issues.
I tried using ...
0
votes
0
answers
44
views
react-table get column head title
I am using @tanstack/react-table React Table in a Next.js application. Want to show a list of columns to select from to display in the display
However, the columns displayed are the column IDs ...
0
votes
1
answer
391
views
Put query into isPlaceholderData with QueryClient methods (while using keepPreviousData)
I have a query that uses placeholderData: keepPreviousData. This means the
query is in a hard loading state, with no placeholder data, on initial mount.
Then, when the queryKey changes, it goes into a ...
0
votes
1
answer
116
views
React-query isRefetching is triger loader in RefreshControl at first mount screen
In my react-native project, I use tanstack react-query: https://tanstack.com/query/latest/docs/framework/solid/reference/useQuery#isrefetching-boolean
Why is isRefetching executed if I don't call ...
0
votes
0
answers
121
views
How to pass extra data to tanstack useMutation?
I have several requests to add and change data:
const updateRwStationsQuery = (id: string, data: RwStationDto) => {
return apiInstance<RwStationDto>(`/rwstations/${id}`, {
method:...
0
votes
0
answers
33
views
How to modify current data with new value from result of separate API calls using React Query
Current Situtaion
Part of my ReactJS app has a social section where users can post messages and reply to other messages.
I have an API call that returns a list of posts, each post contains an id, ...
0
votes
0
answers
316
views
Vite + TanstackRouter + SSR
How to Properly Hydrate a TanStack Router + Vite SSR App Without Using TanStack Start?
I'm trying to implement server-side rendering (SSR) in a TanStack Router + Vite React project without using ...
1
vote
1
answer
159
views
How can I handle 404 error when prefetching data with usePrefetchQuery?
I use an infinite list for which I prefetch data on the app startup. Everything works great except for when I hit 404 error if, for example, I manually change the url to a wrong one. Then the whole ...
0
votes
2
answers
245
views
How to refetch from a client component with useQuery
I have a client component that fetches the list of project and a dialog box that creates a project but I cant update the project list unless I have to do a manual refresh on the browser.
The flow is:
...
-1
votes
1
answer
93
views
React Tanstack Query cache update
React Query not updating my list on first render
My list is not updating when i come back after updating my list , but my api is returning updated data
export default function App() {
const [id] = ...
1
vote
1
answer
316
views
Unknown timeout error when refetching a query
I am having a dumb moment. I use Tanstack Query and Ky in my app to make requests and inject jwt tokens in them. Every time a request hits a 403 error, the request gets resent after acquiring a new ...
4
votes
0
answers
352
views
How to test useSuspenseQuery hook
Recently I read about new hook useSuspenseQuery provided in @tanstack/react-query v5.
Previously I have used useQuery and have written unit tests on it.
I am trying to write unit tests on ...
0
votes
1
answer
154
views
How to invalidate a query with specific parameters using queryClient.invalidateQueries in React Query v5
I’m using React Query to manage my queries, and I have a scenario where I need to invalidate a query with specific parameters.
useQuery({
queryKey: ["users", { page: 2, pageSize: 20 }],
queryFn: ()...
0
votes
0
answers
37
views
React Tanstack Query useInfiniteQuery network issue
I have a React app with a profile outlet route, where the index is the 'products'. I also have a similar route called 'savedProducts'. The difference is that the 'products' page lists by outletparam (...
1
vote
0
answers
224
views
Using tanstack query for async task management
This stack overflow post talks about the when to use the mutation hook vs the useQuery hook. The gist of it was:
If you're reading data: useQuery
If you're creating/updating/deleting data: ...
0
votes
1
answer
464
views
implement simple pagination in Nextjs 15X
I am Vue developer for years ,
now I am trying to learn Reactjs and Nextjs.
and I am implementing user list page that include pagination ,
I have some problem with that
this is my code :
"use ...
0
votes
1
answer
74
views
React Query Caching
With my site I am using Tanstack react-query. Now caching seems to work when navigating between pages and I can confirm that by checking the network log and no extra calls are made.
Now is it fair to ...
3
votes
0
answers
441
views
useInfiniteQuery fails on React Native with "observer.getCurrentResult is not a function" error in @tanstack/react-query ^5.66.3 or higher
When using useInfiniteQuery in React Native environments (Android and iOS), the app crashes with the error: "observer.getCurrentResult is not a function (it is undefined)". This error does ...
0
votes
1
answer
309
views
how to use React Query (TANStack) in next js server components?
A lot of people are saying that use React Query for efficient data retrieval. But to use useQuery hook I have to make every component "client component" then what would be the purpose of SSR ...
0
votes
1
answer
150
views
Unnecessary re-rendering and API calls using Tanstack table and Tanstack Query
I'm using React with @tanstack/react-table and react-query to implement a paginated table with server-side filtering and sorting. I'm encountering an issue where selecting a date filter sometimes ...
0
votes
1
answer
414
views
Why is react-query invalidation bleeding across tabs?
I have 2 instances of storybook running an application locally. I have 2 tabs open on localhost:6006 and localhost:6007, and I log in as a different user on each.
I do things in 1 tab that ...
0
votes
1
answer
1k
views
Canceling a react-query mutation
I have a mutation that comprises of a sequence of long-running actions:
useMutation({
mutationFn: async () => {
await firstTask()
await secondTask()
await thirdTask()
},
...
})
I ...
3
votes
2
answers
965
views
Handling two cache keys for the same data in react-query
I have a Project type in my app. I need to be able to access it via two separate async function:
getProductBySlug
getProductById
At the root of the page I use the URL to derive the slug and query ...
2
votes
1
answer
963
views
Adding Tanstack react-query to laravel 11 reactjs inertia project
Any idea how to add tanstack react-query to laravel 11 reactjs project?
The apps.jsx looks like this
const appName = import.meta.env.VITE_APP_NAME || 'Laravel';
createInertiaApp({
title: (title) =...
0
votes
1
answer
586
views
Next js react query v5 useSuspenseQuery, 401 unathorized
I want to use useSuspenseQuery along with next js so that I can take advantage of the built-in React feature.
But when using useSuspenseQuery, it gives an error img
query
const { data, isLoading } = ...
1
vote
1
answer
182
views
Does the refetch interval timer begin at the start of a request or after the request completes?
If refetchInterval is set to 10 seconds in useQuery, and a given request takes 2 seconds to complete, will the next request be initiated 10 seconds after the start of the previous request, or 10 ...
0
votes
1
answer
513
views
React Query in Expo wont refetch
I'm building an Expo React Native app using Expo Navigation (Stack Navigator) and React Query. When navigating between screens (e.g., from Home to Test screen and back), I need to refetch data when ...
1
vote
0
answers
102
views
Why Does My PATCH Request Occasionally Fail with Status Code 0
Problem Statement
I'm experiencing intermittent failures with a PATCH API request that runs every 20 seconds in a React application. The failures return status code 0 and seem to persist for a long ...
1
vote
1
answer
108
views
ReactQuery invalidateQuery doesn't work, UI updated with optimistic updates but data is not re-fetched
I use optimistic updates for the UI and it works, but the data is not re-fetched. In the server terminal I see only a DELETE request. There should be a GET right after it
queryClient.js
import { ...
0
votes
0
answers
99
views
Angular 19 SSR NodeAppEngine
I am trying to implement hydration of tanstack query cache from server to client.
During the server phase, some requests are cached.
I want to re-use them in the client after hydration process.
I am ...
0
votes
1
answer
91
views
Prevent unnecessary re-renders when updating search state in React Native with TanStack Query
I’m developing a screen in React Native that lists books fetched from my API using TanStack Query. I’ve also implemented a search functionality that updates the results based on the entered text (...
0
votes
2
answers
1k
views
NextJS + React Query + Zustand
Prerequisites
NextJS 14+
Using server action
Using app router
React Query 5+
Zustand+
Question
I wanted to come up with a design that takes advantage of the best of all the tech above.
Imagine we ...
2
votes
1
answer
943
views
How to retain previous data while fetching new data with useInfiniteQuery when using search queries?
I'm using @tanstack/react-query with the useInfiniteQuery hook to fetch paginated data for a list of items. The infinite query works fine for normal pagination and scrolling. However, when I change ...
0
votes
1
answer
527
views
React Query: clear data before refetch
Really simple thing, if a URL parameter changes, previous data is no longer valid and should be cleared. However, when calling refetch from useEffect, useQuery doesn't do that.
Is there some parameter ...
0
votes
1
answer
55
views
How to handle error so that it stops function execution
It goes to the onError in the mutation, however in the try catch the next response has a status of 200 so it does not execute the catch method. What should I do so that if it goes to onError, it goes ...
2
votes
2
answers
418
views
Persisting error state in react-query until successful refetch
I'm using React Query to fetch a list of users via the useQuery hook. When the fetch fails, I display an error message along with a retry button. When I call refetch, both isError and error are ...