T
TanStack•3y ago
apparent-cyan

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
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-cyan
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
sensitive-blue
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
apparent-cyan
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
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-cyan
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
No description
No description
No description
apparent-cyan
apparent-cyanOP•3y ago
I fixed it by removing 'async' on my hooks
harsh-harlequin
harsh-harlequin•3y ago
Asynchronous functions always return a promise, hence the return value type. Hooks must be synchronous.

Did you find this page helpful?