Looking at the manner in which one can import react components in NextJS:
- Plain old static import:
import Component from './Component';
[...]
return (
<Component />
)
- Dynamic import:
import dynamic from 'next/dynamic'
const DynamicComponent = dynamic(() =>
import('../components/hello').then((mod) => mod.Hello)
)
[...]
return (
<DynamicComponent />
)
- Dynamic import with ssr = false:
import dynamic from 'next/dynamic'
const DynamicComponentWithNoSSR = dynamic(
() => import('../components/hello3'),
{ ssr: false }
)
[...]
return (
<DynamicComponentWithNoSSR />
)
My question is simple: When is the 2nd option the preferred option? (In all three cases, imagine that SSR is enabled through the presence of getServerSideProps.)
It seems that in any case my component is client-side-only or triggered by a user action, I'd want Option #3. And it seems that in any case it needs to be SSR'd, if I choose option #2, the chunk file gets downloaded immediately, during the before-hydration
phase, so it doesn't appear to be saving me any time. It just appears to add a network call. So why wouldn't I just use Option #1?
What's the actual use case for Option #2?