Is there a way on react-query to trigger all my fetch upon refresh?
after rigger fetch app can only trigger each fetch depends onFocus screen?
8 Replies
harsh-harlequin•3y ago
Hi 👋
Unless you're persisting the query cache and have configured it not to do so, it will automatically run enabled queries on a hard refresh. What exactly is the problem here?
apparent-cyanOP•3y ago
my problem is when my app was reload i want to fetch all the api(getMethod) - I dont know which is perfect to use(useQueries as a whole or make a useQuery 1 by 1)
then also I want to get specific useQuery attributes to its belong Component
*aAP
const queryTodo = useQuery({ queryKey: ['todos'], queryFn: getTodos })
const queryStarWars = useQuery({ queryKey: ['startwar'], queryFn: getStarWars })
*todo.js
I want to get the data of queryTodo like (isFetching, isLoading) thanks
I want to get the data of queryTodo like (isFetching, isLoading) thanks
sensitive-blue•3y ago
useQuery returns an object with all those properties, so just something like queryTodo.isLoading
https://tanstack.com/query/v4/docs/react/reference/useQuery
useQuery | TanStack Query Docs
const {
data,
apparent-cyanOP•3y ago
what if queryTodo was declared or called on App Component. is there a way to call queryTodo.isLoading on Todos Component?
inland-turquoise•3y ago
It’s possible to call useQuery with the same key again in the sub component. But there’s risk of it refetching if the sub component render is delayed somehow. You can view the discussions here https://github.com/TanStack/query/discussions/2018 on some of the way to go around it. Though personally I’d just pass the query from the parent component down
GitHub
How can I avoid doing a refetch of an stale, but active query? · Di...
Lets say I have a component A that uses a query (wrapped in a custom hook that we will call useUser). Since I have the default config of staleTime set to 0, this query is stale as soon as it mounts...
apparent-cyanOP•3y ago
hi need some help guys; I made a react-query hooks and called it on a component but when I call it it returns Promise <fulfilled>. thanks



apparent-cyanOP•3y ago
I fixed it by removing 'async' on my hooks
harsh-harlequin•3y ago
Asynchronous functions always return a promise, hence the return value type. Hooks must be synchronous.