Hint: Client components need 'use client' directive to render hooks [OK]
Common Mistakes:
Assuming ClientComponent renders without 'use client'
Thinking fetch usage causes error here
Believing nested client components always render
4. Identify the error in this Next.js component interleaving code:
'use client';
export default function ClientComponent() {
const data = fetch('https://api.example.com/data').then(res => res.json());
return <div>Data count: {data.length}</div>;
}
medium
A. Missing 'use server' directive at the top of the file.
B. The component should not return JSX inside a client component.
C. Using fetch directly in a client component without async/await causes a Promise error.
D. The fetch URL is invalid syntax.
Solution
Step 1: Understand fetch in client components
fetch returns a Promise; using it directly without awaiting causes data to be a Promise, not the actual data.
Step 2: Identify the error in rendering
Trying to access data.length on a Promise causes runtime error because Promise has no length property.
Final Answer:
Using fetch directly in a client component without async/await causes a Promise error. -> Option C
Quick Check:
Fetch returns Promise; must await in client [OK]
Hint: Always await fetch in client components to get data [OK]
Common Mistakes:
Thinking 'use server' is needed in client components
Believing JSX can't be returned in client components
Assuming fetch URL syntax is wrong
5. You want to display a list of products fetched on the server and allow users to add products to a cart on the client. Which is the best way to interleave server and client components in Next.js?
hard
A. Fetch products in a server component and render a client component for the add-to-cart buttons inside it.
B. Fetch products inside a client component and handle add-to-cart in the same component.
C. Fetch products in a client component and render server components for buttons.
D. Fetch products and handle add-to-cart both in server components only.
Solution
Step 1: Separate data fetching and interactivity
Fetching products is best done on the server for performance and SEO benefits.
Step 2: Use client components for user actions
Add-to-cart buttons require client interactivity, so they should be client components nested inside the server component.
Final Answer:
Fetch products in a server component and render a client component for the add-to-cart buttons inside it. -> Option A
Quick Check:
Server fetch + client interactivity = Fetch products in a server component and render a client component for the add-to-cart buttons inside it. [OK]
Hint: Server fetch data, client handle clicks inside [OK]
Common Mistakes:
Fetching data on client causing slower load
Trying to handle interactivity in server components
Rendering server components inside client components incorrectly
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.