0Pricing
Next.js 15 Fullstack (App Router + Server Actions) · 강의

로딩 및 오류 UI

`loading.js`로 로딩 상태를 구현하고 애플리케이션의 `error.js` 경계를 사용하여 오류를 우아하게 처리합니다.

로딩 및 오류 UI은(는) CoddyKit의 무료 Next.js 15 Fullstack (App Router + Server Actions) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Next.js 15 Fullstack (App Router + Server Actions) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Next.js 15 Fullstack (App Router + Server Actions) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Why Loading States Matter

When your Next.js application fetches data, it can take some time. Without any visual feedback, users might think the app is frozen or broken.

  • Improve User Experience: Keep users informed.
  • Reduce Frustration: Prevent perceived slowness.
  • Indicate Progress: Show that something is happening in the background.

Introducing `loading.js`

Next.js App Router provides a special file convention, loading.js, to automatically create a loading UI for a route segment.

When data is being fetched for a page.js or layout.js file, Next.js automatically displays the UI defined in its nearest loading.js sibling or ancestor.

Creating a Simple Loading UI

To create a loading UI, simply add a loading.js file inside a route segment folder. It should export a default React component.

This component will be rendered instantly when the segment is loading.

export default function Loading() {
  return (
    <div style={{ padding: '20px', textAlign: 'center' }}>
      <h2>Loading...</h2>
      <p>Please wait while we fetch the content.</p>
    </div>
  );
}

How `loading.js` Works

Under the hood, loading.js works with React Suspense. Next.js wraps the corresponding page.js and its nested children in a Suspense Boundary.

When any data fetching inside that boundary is pending, the loading.js component is shown as a fallback.

Nested Loading States

You can have multiple loading.js files at different levels of your route. For example, a global loading UI and a more specific one for a sub-route.

Next.js will show the closest ancestor loading.js for the segment that is currently loading.

Handling Application Errors

Just like loading states, errors are a part of any application. Uncaught errors can crash your app, leading to a poor user experience.

Next.js App Router provides a way to gracefully handle errors and display a custom error UI using error.js.

Introducing `error.js`

The error.js file convention allows you to define an error UI that automatically wraps a route segment and its children in a React Error Boundary.

This boundary catches errors that occur during rendering, in event handlers, and in data fetching within its scope.

Creating a Basic Error UI

Similar to loading.js, create an error.js file in a route segment. It must be a React Client Component (use 'use client'; at the top).

It receives error (the error object) and a reset function as props.

'use client';

import { useEffect } from 'react';

export default function Error({ error, reset }) {
  useEffect(() => {
    // Log the error to an error reporting service
    console.error(error);
  }, [error]);

  return (
    <div style={{ padding: '20px', textAlign: 'center', color: 'red' }}>
      <h2>Something went wrong!</h2>
      <button
        onClick={() => reset()} // Attempt to re-render the segment
        style={{ marginTop: '10px', padding: '8px 15px' }}
      >
        Try again
      </button>
    </div>
  );
}

Error Recovery with `reset()`

The reset() function provided to your error.js component is crucial. When called, it attempts to re-render the entire segment that threw the error.

This allows users to try again without navigating away, potentially resolving transient issues.

Quick Check on UI Files

Which statement accurately describes the primary purpose of loading.js in Next.js App Router?

Recap: Loading & Error UI

In this lesson, you learned how to enhance your Next.js application's user experience by implementing visual feedback for loading and error states.

  • loading.js: Displays a temporary UI while data is being fetched, using React Suspense.
  • error.js: Catches errors in a segment and displays a fallback UI, allowing users to attempt recovery with the reset() function.

These conventions help create more robust and user-friendly Next.js applications.

자주 묻는 질문

“로딩 및 오류 UI” 강의는 무료인가요?

네 — “로딩 및 오류 UI” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Next.js 15 Fullstack (App Router + Server Actions) 강의 전체를 잠금 해제할 수 있습니다. Next.js 15 Fullstack (App Router + Server Actions) 강의에는 총 4개의 강의가 포함되어 있습니다.

“로딩 및 오류 UI”에서 뭘 배우나요?

`loading.js`로 로딩 상태를 구현하고 애플리케이션의 `error.js` 경계를 사용하여 오류를 우아하게 처리합니다. 브라우저에서 직접 실행하는 실습 코드로 Next.js 15 Fullstack (App Router + Server Actions)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Next.js 15 Fullstack (App Router + Server Actions)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Next.js 15 Fullstack (App Router + Server Actions)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“로딩 및 오류 UI” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Next.js 15 Fullstack (App Router + Server Actions) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Next.js 15 Fullstack (App Router + Server Actions) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 레이아웃 및 페이지 컴포넌트
  2. 동적 경로 및 매개변수
  3. 로딩 및 오류 UI
  4. 라우트 그룹과 중첩 레이아웃
← Next.js 15 Fullstack (App Router + Server Actions)(으)로 돌아가기