Components

next/dynamic

Use a module-scope dynamic import in a Client Component and render conditionally to defer optional work. SSR is enabled by default; ssr:false belongs in client context.

Formal Syntax & Structure

nextjs syntaxnextjs
import dynamic from "next/dynamic"; dynamic(loader, options?)

Working Example

Example Snippetnextjs
'use client';import dynamic from 'next/dynamic';import {useState} from 'react';const Panel = dynamic(()=>import('./details-panel'),{loading:()=> <p role='status'>Loading details</p>});export default function DetailsToggle(){ const [open,setOpen]=useState(false); return <><button aria-expanded={open} onClick={()=>setOpen(!open)}>{open?'Hide':'Show'} details</button>{open && <Panel/>}</>;}
Next.js Reference