How can I truly CSR (client-side render) some pages in my NextJs application?
The documentation says that the presence of either getServerSideProps
or getStaticSiteProps
in a page would make it pre-render on the server per request or at build time respectively.
Yet again, with the advent of automatic static optimisation NextJs determines automatically whether or not to pre-render a statically in the absence of getServerSideProps
or getInitialProps
— If I understand this statement currently, it means that all pages that don't export the aforementioned server-side functions, will be be statically generated on the server
So my question now is how do I truly render on client side only for pages like dashboard, without having nextjs automatically pre-render due to automatic static optimization?
You can disable SSR for a specific component while exporting it.
const NoSSRYourComponent = () => {
return (
// ... NoSSRYourComponent code
)
}
// export it with SSR disabled
const YourComponent = dynamic(() => Promise.resolve(NoSSRYourComponent), {
ssr: false,
})
export default YourComponent