0
0
NextJSframework~20 mins

Why rendering strategy matters in NextJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Rendering Strategy Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What will this Next.js Server Component render?
Consider this Next.js Server Component that fetches data from an API and renders it. What will be the output when this component is rendered on the server?
NextJS
import React from 'react';

async function getData() {
  return { message: 'Hello from server!' };
}

export default async function Greeting() {
  const data = await getData();
  return <p>{data.message}</p>;
}
A<p>Loading...</p>
B<p>Hello from server!</p>
CError: Cannot use await in component
D<p>undefined</p>
Attempts:
2 left
💡 Hint
Server Components can use async/await to fetch data before rendering.
state_output
intermediate
2:00remaining
What happens when this Client Component updates state?
This Next.js Client Component uses useState to toggle text on button click. What text will be shown after clicking the button twice?
NextJS
"use client";
import React, { useState } from 'react';

export default function ToggleText() {
  const [show, setShow] = useState(true);
  return (
    <>
      <p>{show ? 'Visible' : 'Hidden'}</p>
      <button onClick={() => setShow(!show)}>Toggle</button>
    </>
  );
}
AHidden
BError: useState not allowed
CVisibleHidden
DVisible
Attempts:
2 left
💡 Hint
Each click toggles the boolean state. Two toggles return it to original state.
lifecycle
advanced
2:00remaining
Why does this Next.js component fetch data twice?
This Next.js component fetches data inside a Client Component and also uses a Server Component wrapper. Why might the data fetch happen twice?
NextJS
"use client";
import React, { useEffect, useState } from 'react';

function ClientFetcher() {
  const [data, setData] = useState(null);
  useEffect(() => {
    fetch('/api/data')
      .then(res => res.json())
      .then(json => setData(json));
  }, []);
  if (!data) return <p>Loading...</p>;
  return <p>{data.message}</p>;
}

export default function Page() {
  return <ClientFetcher />;
}
ABecause useEffect runs twice in development mode causing double fetch
BBecause fetch is called synchronously twice in the same render
CBecause the API endpoint returns duplicate data
DBecause Server Component fetches data and Client Component fetches again on mount
Attempts:
2 left
💡 Hint
React Strict Mode in development runs effects twice to help find bugs.
📝 Syntax
advanced
2:00remaining
Which option causes a syntax error in Next.js Server Component?
Identify which code snippet will cause a syntax error when used as a Next.js Server Component.
NextJS
export default function ServerComp() {
  const data = await fetch('https://api.example.com/data');
  return <p>{data.status}</p>;
}
AWrap await in an IIFE inside the function
BRemove await and use .then(): fetch(...).then(data => ...)
CKeep as is without async keyword
DAdd async keyword: export default async function ServerComp() { ... }
Attempts:
2 left
💡 Hint
await can only be used inside async functions.
🔧 Debug
expert
3:00remaining
Why does this Next.js page show stale data after navigation?
A Next.js page fetches data in a Server Component and renders it. After navigating client-side to this page, the data does not update even though the API changed. Why?
NextJS
export default async function Page() {
  const res = await fetch('https://api.example.com/data', { cache: 'no-store' });
  const data = await res.json();
  return <p>{data.message}</p>;
}
ABecause fetch is cached by default and needs { cache: 'no-store' } to refetch
BBecause the API endpoint is down and returns old cached response
CBecause the component is a Client Component and does not refetch on navigation
DBecause the data is stored in localStorage and not updated
Attempts:
2 left
💡 Hint
Next.js Server Components cache fetch results by default for performance.