Consider this loading.tsx file in a Next.js app directory. What will the user see while the page is loading?
export default function Loading() { return <div role="status" aria-live="polite">Loading content, please wait...</div>; }
Check what the component returns and the role attribute used.
The component returns a div with a loading message and role="status" which announces updates to screen readers. This means the message is visible and accessible during loading.
Choose the correct syntax for a loading component in Next.js 14+ using TypeScript.
Next.js expects a default export function named Loading.
Next.js 14+ requires a default exported function named Loading in loading.tsx. Option A matches this pattern exactly.
Given this loading.tsx code, what is the output or behavior during loading?
import { useState, useEffect } from 'react';
'use client';
export default function Loading() {
const [dots, setDots] = useState('');
useEffect(() => {
const interval = setInterval(() => {
setDots(d => (d.length < 3 ? d + '.' : ''));
}, 500);
return () => clearInterval(interval);
}, []);
return Loading{dots};
}Think about how useState and useEffect work together to update UI over time.
The component uses a timer to add dots up to three, then resets. This creates an animated loading message cycling every 500ms.
Examine this loading.tsx code snippet. Why does Next.js show a hydration mismatch warning?
'use client';
export default function Loading() {
const date = new Date();
return Loading at {date.toLocaleTimeString()};
}Consider what happens when server and client render different outputs.
The date/time changes between server render and client hydration, causing React to detect a mismatch in the HTML content.
Choose the best explanation for why Next.js uses a loading.tsx file in the app directory.
Think about what users see when navigating between pages that take time to load.
The loading.tsx file provides a way to show a loading indicator while Next.js fetches data or code for a route, so users get immediate feedback instead of a blank screen.