0
0
NextJSframework~20 mins

Force-dynamic and force-static in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Next.js Rendering Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What happens when you add 'use server' in a Next.js Server Component?
Consider a Next.js Server Component with the directive 'use server' at the top. What is the effect of this directive on the component's behavior?
NextJS
"use server";

export default function MyComponent() {
  return <p>Hello from server!</p>;
}
AThe component is forced to run only on the server and cannot be rendered on the client.
BThe component is forced to run only on the client and cannot be rendered on the server.
CThe component can run both on client and server without restrictions.
DThe component will throw a runtime error because 'use server' is not a valid directive.
Attempts:
2 left
💡 Hint
Think about where server components run in Next.js and what 'use server' enforces.
state_output
intermediate
2:00remaining
What is the output when using 'force-static' in a Next.js page?
Given a Next.js page with the directive 'export const dynamic = "force-static";', what will be the rendering behavior of this page?
NextJS
export const dynamic = "force-static";

export default function Page() {
  return <p>Static content</p>;
}
AThe page will fail to build because 'force-static' is not a valid value.
BThe page is statically generated at build time and served as static HTML.
CThe page is rendered on the client only and never on the server.
DThe page is always rendered dynamically on each request on the server.
Attempts:
2 left
💡 Hint
Consider what 'force-static' means for Next.js page rendering.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly forces dynamic rendering in Next.js?
Select the code snippet that correctly forces a Next.js page to be dynamically rendered on every request.
A
export const dynamic = "force-dynamic";

export default function Page() { return &lt;p&gt;Dynamic page&lt;/p&gt;; }
B
export const dynamic = true;

export default function Page() { return &lt;p&gt;Dynamic page&lt;/p&gt;; }
C
export const dynamic = "dynamic-force";

export default function Page() { return &lt;p&gt;Dynamic page&lt;/p&gt;; }
D
export const dynamic = false;

export default function Page() { return &lt;p&gt;Dynamic page&lt;/p&gt;; }
Attempts:
2 left
💡 Hint
Check the exact string value Next.js expects for forcing dynamic rendering.
🔧 Debug
advanced
2:00remaining
Why does this Next.js page fail to statically generate?
This Next.js page has 'export const dynamic = "force-static";' but still fails to statically generate and instead renders dynamically. Why?
NextJS
export const dynamic = "force-static";

export default function Page() {
  const time = Date.now();
  return <p>Time: {time}</p>;
}
AThe page is missing 'use client' directive, so it cannot be statically generated.
BThe 'force-static' directive is ignored if the component uses any JSX elements.
CThe 'dynamic' export must be a boolean, not a string.
DUsing Date.now() causes the page to depend on runtime data, so Next.js forces dynamic rendering despite 'force-static'.
Attempts:
2 left
💡 Hint
Think about what makes a page static or dynamic in Next.js.
🧠 Conceptual
expert
3:00remaining
How do 'force-dynamic' and 'force-static' affect caching and performance in Next.js?
Explain the impact of using 'force-dynamic' versus 'force-static' on caching behavior and performance in Next.js applications.
A'force-dynamic' caches pages indefinitely on the CDN; 'force-static' forces server rendering on every request.
B'force-dynamic' and 'force-static' have no effect on caching or performance; they only affect styling of components.
C'force-dynamic' disables static caching and renders pages on every request, which can increase server load but ensures fresh data; 'force-static' enables static caching, improving performance but serving stale data until rebuild.
D'force-dynamic' enables aggressive client-side caching, reducing server load; 'force-static' disables caching entirely, causing slower page loads.
Attempts:
2 left
💡 Hint
Consider how static and dynamic rendering affect server work and cache freshness.