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

gradual-turquoise
gradual-turquoise11/27/2022

Is it possible to use react-query with socket io?

for realtime notifications purposes only. Capstone.
adverse-sapphire
adverse-sapphire11/27/2022

Using hydration

I've used this code in my next 12 app: https://tanstack.com/query/v4/docs/guides/ssr#using-hydration But my fetching function uses prisma. Thing is, Prisma cannot be called in the client. So I can't use "useQuery" with it. How should I write my code then? not using hydration and just doing useQuery on my getServerSideProps, without hydration thing?...
afraid-scarlet
afraid-scarlet11/27/2022

RN(Expo) Paused mutations runs before network is fully restored, 'Network request failed'

Hello! I'm developing a mobile app using Expo. I've been following the offline example in the docs (https://tanstack.com/query/v4/docs/examples/react/offline), and it works up until I restore the network connection and try to fire the API call in setMutationDefaults. I get the mutation-variables, and using NetInfo / onlineManager. I can see that the device is online. But when the API-call is made, it errors out and I get TypeError: Network request failed, as if the device isn't online. Has anyone else had this issue? Or is there something obvious I'm missing when using this in combination with react-native? I've read the docs and double checked the official example, but can't figure out what's wrong. Thank you...
optimistic-gold
optimistic-gold11/26/2022

Use react-query with react-blessed

So i'm building a TUI, and i would like to use react-query with react-blessed to fetch data, but it can't find react-dom and crashes, how do i make it work?
stormy-gold
stormy-gold11/26/2022

How to log error from react query?

Hi, I have some problem after migrating to v4 from v3. I checked that react query didn't make any requests (by user's chrome dev tool network tab) without any error log. First, I added code that did not uses react query for the GET request, and unlike react query, it works fine. ...
eager-peach
eager-peach11/26/2022

Paginated queries limiting amount rendered at once

Paginated queries: My API returns 25 items at once, but I only want to render 10 at once. Ideally if you move to page 3 (indexes 20-30) when only 25 items are cached, the 5 cached would render and the other 5 would be loading until the data is fetched....
rare-sapphire
rare-sapphire11/25/2022

Mutation without hooks

After reading this article (https://medium.com/duda/what-i-learned-from-react-query-and-why-i-will-not-use-it-in-my-next-project-a459f3e91887), that states you can only use react-query with hooks and reading react-queries maintainer Dominik Dorfmeister replying that "react-query also is not per se hooks driven" I'm left wondering how one could do mutations without hooks? For queries there is queryClient.fetchQuery, but I found no counterpart for mutations in the docs.
environmental-rose
environmental-rose11/25/2022

Combining useQueries into a single result

Hi All, I'm basically trying to make a custom hook which allows multiple queries to be executed and then all of the results get merged together into a single result set. I currently have this however this doesn't work as the size of result changes between renders as rootData can start as an empty array....
broad-brown
broad-brown11/25/2022

Objects as parameters and keys

Reading this interesting use case i was wondering about queries that are already formated as objects. Let's imagine my queries are like this: get({thing: 'todo'}) => get all todos get({thing: 'todo', id: '0x111'}) => get specific todo...
broad-brown
broad-brown11/25/2022

How to update segments of cache with related queries (or graphQL like)

Hey! I'm curious about how to update cache when different queries update the same resource. 2 quick examples: - i have getTodos() and get Todo(id) => how to make them update each other? For example if i just loaded todo #13, if i go to the list of todos no need to query it again - I query nested entities, for example Book>Author. And then lets say i query Author in a different query....
like-gold
like-gold11/24/2022

how to reset useInfiniteQuery?

hello, I have been stuck for a while on how would i reset my useInfiniteQuery, my case was i implement load more button with infinite query then i want to reset it back to only have 1 pages, how can i do it? i have used refetch, invalidateQueries, resetQueries, none of these works thank you...
adverse-sapphire
adverse-sapphire11/24/2022

Hydrate's purpose is for SSR?

I'm using Next 12, and I saw some examples with and without hydrate. Does its main purpose is to fetch data on the server? Isn't it being done already by using something like getServerSideProps? It adds so much overhead, so I wonder what's its worth...
ratty-blush
ratty-blush11/24/2022

How to support older browsers

Hello all! I'm currently building a project that uses React Query. It's amazing tools and I can integrate with SSR framework. But now I'm struggling to support older browsers. I read the documentation and there is a something like this:
Depending on your environment, you might need to add polyfills. If you want to support older browsers, you need to transpile the library from node_modules yourselves.
...
rare-sapphire
rare-sapphire11/23/2022

Jest testing with RQ and ensuring that the query is done before proceeding

Followed the guidance from https://tanstack.com/query/v4/docs/guides/testing (except I'm using @testing-library/react-native and not @testing-library/react-hooks) Say I got a MenuScreen that contains a lot of MenuLink ```ts...
rival-black
rival-black11/22/2022

retry after an async call

hello im trying to implement a refresh token flow with react query when I encounter a 401 i want to make a call to get a new token and swap it THEN retry. any ideas on how to pull this off leveraging what query gives me or should i go custom(keep it outside of query)...
optimistic-gold
optimistic-gold11/22/2022

Query selector returning old data

I have an API that returns the new record on create/update so I am using setQueryData inside the update mutation to update the cache instead of invalidating and refetching. In my app I show the list of records, with an option to hide some inactive records. ``` const showActiveOnlyFn = (records) => records.filter(r => r.active)...
stormy-gold
stormy-gold11/22/2022

React Query v3.39.2 Devtools not showing up using Vite v3.1.1

The devtool icon does not appear. I have tried adding NODE_ENV=development to process.env using a vite plugin called vite-plugin-environment like this: EnvironmentPlugin(["NODE_ENV"]) . I have confirmed that process.env.NODE_ENV === "development" but the icon still doesn't appear.
manual-pink
manual-pink11/22/2022

Slightly stuck debugging a query invalidation not working

I have a useInfiniteQuery with a cachekey that starts with 'MyTable' (keepPreviousData is true, I also disabled refetchOnWindowFocus since otherwise navigating to the devtools window would reset things. No other settings are set.) I have a mutation that that, onSuccess, invalidates ['MyTable']. I confirmed that on invalidation we refetch updated data from the network - that useInfiniteQuery is the only query to make that particular api call....
ratty-blush
ratty-blush11/21/2022

mutate in loop cause infinite re renders

usecase: I have orders coming from other hooks wraped around useQuery I am getting orders from those hook What i need to do ...
stormy-gold
stormy-gold11/21/2022

How to sync client with server state?

Hey there, I have a Create Post component has a button that opens a sidebar (drawer) that allows me to select the categories (think checkboxes) and I need to reflect the selected categories back to the Create Post component (I'm fetching the categories using react-query). In order to display selected categories back in Create Post component, I'm using Recoil to store the selected categories. However, I'm worried with this approach (or I'm thinking too much). The point is, if a category is deleted, the data won't be in sync (when react-query refetch categories, maybe I can end up with a deleted category in state). In this example, imagine the "categoriesSelected" containing category "typescript", when it shouldn't because it was deleted. In the end, categories component will show all the correct categories, but the create component will show a non-existing category!...