0
0
NextJSframework~20 mins

Dynamic rendering triggers in NextJS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Dynamic Rendering Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What triggers a re-render in a Next.js Server Component?
Consider a Next.js Server Component that fetches data and renders it. Which action below will cause the component to re-render on the server?
NextJS
export default async function UserProfile({ userId }) {
  const user = await fetch(`https://api.example.com/users/${userId}`).then(res => res.json());
  return <div>{user.name}</div>;
}
AChanging the userId prop passed to the component
BUpdating a client-side state variable inside the component
CClicking a button inside the component without navigation
DModifying a CSS file imported by the component
Attempts:
2 left
💡 Hint
Think about what causes the server to fetch new data and re-run the component function.
state_output
intermediate
2:00remaining
What is the output after client interaction in a Next.js app with Server and Client Components?
Given a Next.js page with a Server Component rendering a Client Component that has a button to update local state, what will be displayed after clicking the button?
NextJS
export default function Page() {
  return <ClientCounter />;
}

'use client';
import { useState } from 'react';

function ClientCounter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(count + 1)}>Count: {count}</button>;
}
AThe button text updates to 'Count: 1' immediately after click
BThe button text remains 'Count: 0' because Server Components do not update
CThe page reloads and resets the count to 0
DAn error occurs because useState cannot be used in Next.js
Attempts:
2 left
💡 Hint
Remember where useState works and how Client Components behave.
📝 Syntax
advanced
2:00remaining
Which code snippet correctly uses dynamic rendering with Next.js App Router's fetch caching?
You want to fetch fresh data on every request in a Server Component using Next.js App Router. Which code below correctly disables fetch caching to ensure dynamic rendering?
Aconst data = await fetch('https://api.example.com/data', { cache: 'reload' }).then(res => res.json());
Bconst data = await fetch('https://api.example.com/data', { cache: 'no-store' }).then(res => res.json());
Cconst data = await fetch('https://api.example.com/data', { cache: 'force-cache' }).then(res => res.json());
Dconst data = await fetch('https://api.example.com/data', { cache: 'default' }).then(res => res.json());
Attempts:
2 left
💡 Hint
Check Next.js fetch cache options for dynamic data fetching.
🔧 Debug
advanced
2:00remaining
Why does this Next.js Server Component not re-render when expected?
A developer expects this Server Component to re-render when the URL query changes, but it does not. What is the likely cause?
NextJS
import { useSearchParams } from 'next/navigation';

export default function Page() {
  const searchParams = useSearchParams();
  const filter = searchParams.get('filter');
  return <div>Filter: {filter}</div>;
}
AThe component should use useRouter instead of useSearchParams
BThe component lacks a useEffect to watch searchParams changes
CuseSearchParams is a client hook and cannot be used in Server Components
DThe fetch call inside the component is missing to update data
Attempts:
2 left
💡 Hint
Check which hooks are allowed in Server Components.
🧠 Conceptual
expert
3:00remaining
Which Next.js rendering strategy ensures a page updates on every request but still benefits from partial caching?
You want a Next.js page that fetches fresh data on every request but also caches static assets and layout parts. Which rendering strategy achieves this?
AUse Client Components with useEffect fetching data on mount
BUse getServerSideProps to fetch data on every request
CUse getStaticProps with revalidate set to 0
DUse Server Components with fetch cache set to 'no-store' and static layouts
Attempts:
2 left
💡 Hint
Consider Next.js App Router features for partial caching and dynamic data.