"use server"; export default function MyComponent() { return <p>Hello from server!</p>; }
The 'use server' directive forces the component to be a server component, meaning it only runs on the server and never on the client. This helps Next.js optimize rendering and data fetching.
export const dynamic = "force-static"; export default function Page() { return <p>Static content</p>; }
Setting 'dynamic' to 'force-static' tells Next.js to generate the page statically at build time, serving the same HTML for every request without server-side rendering.
The correct way to force dynamic rendering is to export 'dynamic' with the string value 'force-dynamic'. Other values are invalid or have different meanings.
export const dynamic = "force-static"; export default function Page() { const time = Date.now(); return <p>Time: {time}</p>; }
Using Date.now() introduces runtime data that changes on every request, so Next.js cannot statically generate the page even if 'force-static' is set.
'force-dynamic' disables static generation, so pages are rendered on each request, ensuring fresh data but increasing server load. 'force-static' generates pages at build time, enabling caching and faster loads but data may be stale until next build.