'How to fetch user details only once
I have several components that make use of user details.
Since user details don't change that often, I want to fetch them only once.
One way would be -
const twentyFourHoursInMs = 1000 * 60 * 60 * 24
defaultOptions: {
queries: {
refetchOnWindowFocus: false,
refetchOnmount: false,
refetchOnReconnect: false,
retry: false,
staleTime: twentyFourHoursInMs,
},
},
})
Other way is to fetch data once in base component and use cached data in other components by using queryClient.getQueryData('user')
Which way would be better?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
