-
I'm getting "window is not defined" on first load when attempting to use Steps to reproduce are to simply attempt to use "useMutation" inside of another hook, and then import that into a component. I'm even using |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
A bit more context — I am importing a component into a "page" in NextJS, and that component is importing my custom hooks with either mutations or queries. A simple workaround is to make these imports dynamic, so as an example. // page.tsx
// Home page in NextJS importing custom components
const ShowPosts = dynamic(() => import('@/components/ShowPosts'), {
loading: () => <Spinner />,
ssr: false,
});
export default function Home() {
return (
<main>
<ShowPosts />
</main>
);
}
// ShowPosts.tsx
// Component that is importing my own custom hooks using react-query
export default function ShowPosts() {
// custom hooks for api calls using queries and mutations
const { data } = useApiQuery<Post[]>({ model: 'post', command: 'read' });
const { mutate: deletePost } = useApiMutation<Post>({
model: 'post',
command: 'delete',
});
return (
<div>
{data?.map((post) => (
<PostListItem key={post.id} {...{ post, deletePost }} />
))}
</div>
);
} |
Beta Was this translation helpful? Give feedback.
-
we have window checks for SSR purposes, so there shouldn't be any errors like that. I can take a closer look if you can provide a sandbox that shows that issue. |
Beta Was this translation helpful? Give feedback.
A bit more context — I am importing a component into a "page" in NextJS, and that component is importing my custom hooks with either mutations or queries. A simple workaround is to make these imports dynamic, so as an example.