Codesnippet.dev
</>

Disable SSR for a component in Next.js

Sometimes you want to disable SSR for a component. e.g. in case it's dependent on window. The following snippet shows how to do it.

import dynamic from "next/dynamic";
const ComponentWithDisabledSSR = dynamic(() => import("./ClientOnly"), {
ssr: false,
});
const ExamplePage = () => {
return (
<div>
<ComponentWithDisabledSSR />
</div>
);
}
export default ExamplePage;