Skip to main content
The 2024 Developer Survey results are live! See the results

Questions tagged [react-query]

React Query is hooks-based library for integrating data fetching into React function components

196 votes
14 answers
243k views

React-Query: How to useQuery when button is clicked

I am new to this react-query library. I know that when I want to fetch data, with this library I can do something like this: const fetchData = async()=>{...} // it starts fetching data from ...
Leem.fin's user avatar
  • 42k
96 votes
18 answers
148k views

"Error: No QueryClient set, use QueryClientProvider to set one"

I was trying React Query and got this at the start of my React app. import React from 'react' import { useQuery } from "react-query"; const fetchPanets = async () => { const ...
Jamal's user avatar
  • 1,211
75 votes
9 answers
68k views

What is the main difference between React Query and Redux?

currently I am using redux in different projects for state management. A few days back, I listened about react-query which is also used for state management and provides caching and async fetching. I ...
Sanan Ali's user avatar
  • 3,189
58 votes
2 answers
53k views

Conditionally calling an API using React-Query hook

I am using react-query to make API calls, and in this problem case I want to only call the API if certain conditions are met. I have an input box where users enter a search query. When the input value ...
Tom Harvey's user avatar
  • 4,133
54 votes
4 answers
25k views

what is difference between tanstack/react-query and react-query

As these are downloadable from npm with their names with different sizes. In which scenarios we must downloads tanstack react query and for which react-query.
Jahangir Hussain's user avatar
45 votes
2 answers
60k views

What are staleTime and cacheTime in React-Query?

I have read React Query docs. Still, I do not understand how to use staleTime & cacheTime for data caching. I want to store data for 2 mins in the cache after first-time API call. No matter if the ...
meet d's user avatar
  • 578
36 votes
22 answers
63k views

Invalidate queries doesn't work [React-Query]

I'm trying to invalidate queries every times users press button "likes" to refresh all queries but without success so far despite following the docs. I have a component that get data : ...
yoann84's user avatar
  • 723
34 votes
2 answers
43k views

How to call useQuery hook conditionally?

Because of the Rules of Hooks, one shouldn't call hooks conditionally. So how does one fetch data conditionally using useQuery? For example, let's say I want to fetch data inside a functional ...
M. M's user avatar
  • 570
31 votes
2 answers
106k views

What is the correct way to pass parameters to a React-query useQuery method that uses Axios

I am currently building a Ruby on Rails Webpacker application with a React front end. I am at the point where I would like to create all the quires I need to make calls to my Rails API. I was loosely ...
humbledev7000's user avatar
31 votes
7 answers
74k views

Is there any solution to mock react-query's useQuery and useMutation while working with react testing library

I'm working on test cases with react testing library. To write the test case I need to mock the useQuery and useMutation method of react query. If anyone knows the solution please guide me. I'm adding ...
Rahul's user avatar
  • 311
30 votes
1 answer
41k views

react-query: onSuccess, onError, onSettled are deprecated. What should I use instead?

In this code snippet, when I hover over the onSuccess callback, it says that it's deprecated and will be removed in the next major version. The same happens with onError and onSettled callbacks. What ...
netrolite's user avatar
  • 1,770
28 votes
3 answers
62k views

react-query: Refetch Query only if the state variable is changed

I have a select option menu. So, When a user selects an option, I want send a GET/ request to the server with that option and recieve the filtered data from server. This can be achived using useEffect(...
Ashik's user avatar
  • 3,278
26 votes
3 answers
30k views

react-query - What's the difference between useQuery and useMutation hook?

Trying to find an answer regarding react-query. What's the difference between useQuery and useMutation? From what i understand useQuery's are dependent calls. useMutation are for posts that require ...
chrisjlee's user avatar
  • 22.5k
25 votes
5 answers
40k views

Access data already fetched with react query in other component

I'm new with React Query, and I have a question, I've being looking on the documentation but I can't find how should I access the data that is already fetched with useQuery() from another component. I'...
Peace Brother Peace's user avatar
25 votes
6 answers
60k views

How to handle multiple queries with React-Query

I've started playing with React-Query and it works great if I only need to fetch data from a single collection in my database. However, I'm struggling to find a good way to query multiple collections ...
Beadle's user avatar
  • 459

15 30 50 per page
1
2 3 4 5
122