0
0
NextJSframework~20 mins

Why advanced patterns solve complex UIs in NextJS - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Advanced Frameworks Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
component_behavior
intermediate
2:00remaining
What is the output of this Next.js Server Component?
Consider this Next.js Server Component that fetches data and renders a list. What will be the rendered output?
NextJS
import React from 'react';

async function getData() {
  return ['apple', 'banana', 'cherry'];
}

export default async function FruitList() {
  const fruits = await getData();
  return (
    <ul>
      {fruits.map((fruit) => (
        <li key={fruit}>{fruit.toUpperCase()}</li>
      ))}
    </ul>
  );
}
A<ul><li>APPLE</li><li>BANANA</li></ul>
B<ul><li>APPLE</li><li>BANANA</li><li>CHERRY</li></ul>
CSyntaxError: Unexpected token 'await' in function
D<ul><li>apple</li><li>banana</li><li>cherry</li></ul>
Attempts:
2 left
💡 Hint
Remember that Server Components can use async/await directly and the map transforms each fruit to uppercase.
state_output
intermediate
2:00remaining
What is the displayed count after these React state updates?
In this React functional component using hooks, what number will be displayed after clicking the button twice quickly?
NextJS
import React, { useState } from 'react';

export default function Counter() {
  const [count, setCount] = useState(0);

  function increment() {
    setCount(count + 1);
    setCount(count + 1);
  }

  return (
    <>
      <p>Count: {count}</p>
      <button onClick={increment}>Add 2</button>
    </>
  );
}
ACount: 0
BCount: 2
CCount: 1
DCount: 4
Attempts:
2 left
💡 Hint
Remember that React state updates are asynchronous and batched, so multiple setCount calls with the same value do not accumulate.
📝 Syntax
advanced
2:00remaining
Which option correctly uses Next.js 14 App Router server action syntax?
Next.js 14 introduces server actions for form handling. Which code snippet correctly defines a server action to handle a form submission?
A
export async function action() {
  'use server';
  const name = formData.get('name');
  return `Hello, ${name}`;
}
B
export async function action(formData) {
  const name = formData.get('name');
  return `Hello, ${name}`;
}
C
export function action(formData) {
  'use server';
  const name = formData.get('name');
  return `Hello, ${name}`;
}
D
export async function action(formData) {
  'use server';
  const name = formData.get('name');
  return `Hello, ${name}`;
}
Attempts:
2 left
💡 Hint
Server actions must be async functions and include the 'use server' directive inside the function body.
🔧 Debug
advanced
2:00remaining
Why does this React component cause an infinite render loop?
Examine this React component. Why does it cause an infinite render loop?
NextJS
import React, { useState, useEffect } from 'react';

export default function Loop() {
  const [count, setCount] = useState(0);

  useEffect(() => {
    setCount(count + 1);
  }, [count]);

  return <p>Count: {count}</p>;
}
ABecause useEffect updates state on every count change, triggering itself repeatedly.
BBecause setCount is called outside useEffect causing immediate re-renders.
CBecause count is not initialized properly causing undefined behavior.
DBecause useEffect has an empty dependency array causing no updates.
Attempts:
2 left
💡 Hint
Think about what happens when state changes inside a useEffect that depends on that state.
🧠 Conceptual
expert
3:00remaining
Why do advanced patterns like React Server Components improve complex UI performance?
Select the best explanation for why React Server Components help solve performance issues in complex user interfaces.
AThey allow rendering parts of the UI on the server, reducing client JavaScript and improving load times.
BThey force all UI logic to run on the client, increasing interactivity but slowing initial load.
CThey replace React hooks with class components for better lifecycle control.
DThey require all data fetching to happen on the client, increasing network requests.
Attempts:
2 left
💡 Hint
Think about where rendering happens and how that affects client load and interactivity.