Issue with useQuery initialData #6878
Replies: 1 comment
-
I found the problem. The problem was on CachedData interface. interface CachedData {
pages: Photo[][];
pageParams: number[];
} In fact, pages is an array of Photo array. and here is the initialData option: initialData: () => {
const cachedData = queryClient.getQueryData<CachedData>(["photos"]);
if (cachedData) {
return cachedData.pages
.flat()
.find((photo) => photo.id === parseInt(params.id));
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using react-query v5 in a next.js 14 project. The problem is that I cannot retrieve cached photo in photo detail component via initialData option.
here is the first component where i fetch a list of photos from jsoanplaceholder api:
and here is the photo detail component in which i try to avoid loading state by fetching photo from the cache:
But i still see "Loading ..." state and nothing is fetched from the cache.
Beta Was this translation helpful? Give feedback.
All reactions