Closed cansin closed 8 months ago
I.e. this file is used in two places:
import { useTasks } from './useTasks';
export default function SomeClientComponent() {
const { data: tasks = [] } = useTasks();
return <>{tasks}</>
}
and also from a server page like:
import {
HydrationBoundary,
QueryClient,
dehydrate,
} from '@tanstack/react-query';
import { getCookies } from 'next-client-cookies/server';
import { fetchTasks } from './useTasks';
export default async function SomePage() {
const cookies = getCookies();
const queryClient = new QueryClient();
await queryClient.prefetchQuery({
queryKey: tasksQueryKey(),
queryFn: () => fetchTasks({ cookies }),
});
return (
// Neat! Serialization is now as easy as passing props.
// HydrationBoundary is a Client Component, so hydration will happen there.
<HydrationBoundary state={dehydrate(queryClient)}>
<SomeContent />
</HydrationBoundary>
);
}
Ah, I guess I could separate the file in the interim 🤷
Nope, that did NOT help. 🤔
Can you share a repo with reproduction of this issue?
We have an example of a working project: https://github.com/moshest/next-client-cookies/tree/main/demo
It's probably related to something within your configuration and not this package.
Just had the same error. You need to add "use client" at the top of the your client source.
I have a React hook where there is also query getter defined for an axios call. E.g.
The
import { useCookies } from 'next-client-cookies';
import statement causes application to crush with: