Which of the following best explains why using design patterns improves the architecture of a Next.js application?
Think about how patterns help teams work together and keep code organized.
Design patterns offer proven solutions and a shared vocabulary. This helps developers understand each other's code and maintain it more easily over time.
In Next.js, what is the main benefit of separating components into Container and Presenter parts?
Think about how separating concerns helps keep code clean and testable.
The Container-Presenter pattern splits responsibilities: Containers handle data and logic, Presenters handle UI. This separation makes components simpler and easier to maintain.
Which option correctly uses the getServerSideProps function to fetch data for a page in Next.js?
Remember that getServerSideProps must return an object with a props key containing an object.
Option D correctly awaits the fetch and json calls, then returns an object with props containing the data. Other options either miss await or return incorrect structures.
Given this Next.js component, why does it cause a hydration mismatch error?
export default function Counter() {
const [count, setCount] = React.useState(Math.floor(Math.random() * 10));
return (
<div>
<p>Count: {count}</p>
<button onClick={() => setCount(count + 1)}>Increment</button>
</div>
);
}Think about what happens when server and client render different initial values.
Using Math.random() in initial state causes the server to render one value and the client another, leading to hydration mismatch errors.
In Next.js 14+, which statement about useEffect in Server Components is true?
Recall the difference between Server and Client Components in Next.js.
Server Components render only on the server and do not run client-side hooks like useEffect. useEffect runs only in Client Components after hydration.