Next.js supports server-side rendering (SSR) out of the box. How does this help improve SEO compared to a plain React app?
Think about how search engines read web pages and what they see first.
Next.js pre-renders pages on the server, sending complete HTML to the browser. This means search engines get the full content immediately, improving SEO. Plain React apps often rely on client-side rendering, which can delay content visibility to crawlers.
Next.js uses a file-based App Router system. What is a key difference in behavior compared to using React Router in a plain React app?
Consider how routes are created and maintained in both systems.
Next.js uses the file system to define routes automatically, so developers don't need to write route configs. React Router requires explicit route definitions in code. This makes Next.js routing simpler and less error-prone.
Consider the lifecycle of data fetching in Next.js using server components versus client-side fetching in React. What is a key difference?
Think about when and where data is fetched in Next.js compared to React.
Next.js supports server components and server-side data fetching, so data can be loaded before the page reaches the browser. This reduces or eliminates loading spinners on the client. Plain React apps usually fetch data after the page loads, causing loading states.
Next.js server components are React components that run on the server. Which snippet correctly defines a server component in Next.js 14+?
Remember server components do NOT have the "use client" directive.
In Next.js 14+, a component without the "use client" directive is a server component by default. Option A defines a simple server component. Option A is a client component. Option A uses a non-existent API. Option A mixes runtime config but does not affect server component syntax.
Given this Next.js page code, why does it cause a server rendering error?
import { useState } from 'react';
export default function Page() {
const [count, setCount] = useState(0);
return ;
}import { useState } from 'react'; export default function Page() { const [count, setCount] = useState(0); return <button onClick={() => setCount(count + 1)}>Count: {count}</button>; }
Think about client vs server components and hooks usage.
In Next.js, components that use React hooks like useState must be client components. This requires adding the "use client" directive at the top. Without it, Next.js treats the component as a server component, which cannot use hooks, causing a server rendering error.