nextJs

nextJs의 ErrorHandling

woojin06 2025. 9. 16. 17:27

https://nextjs-ko.org/docs/app/building-your-application/routing/error-handling

 

Error Handling – Nextjs 한글 문서

Learn how to display expected errors and handle uncaught exceptions.

nextjs-ko.org

 

nextJs 프로젝트를 시작 하기 전 해당 글을 읽으며 이해가 안된 부분이 있었다. 

'use client' // Error boundaries must be Client Components
 
export default function GlobalError({
  error,
  reset,
}: {
  error: Error & { digest?: string }
  reset: () => void
}) {
  return (
    // global-error must include html and body tags
    <html>
      <body>
        <h2>Something went wrong!</h2>
        <button onClick={() => reset()}>Try again</button>
      </body>
    </html>
  )
}

해당 예제인데 해당 페이지엔 props로 받아오는 error와 reset 구문을 어디에도 찾을 수 없었고

reset의 역할이 궁금했는데 처음엔 refetch로 해당 페이지에 api만 재호출 하는 개념으로 이해 중이었다.

하지만 찾아보니

 

출처: https://velog.io/@ysy06053/Next.js-%EC%97%90%EB%9F%AC-%ED%95%B8%EB%93%A4%EB%A7%81

해당 블로그를 찾아보니 refetch 개념이 아닌 단순 re-render 역할이었다.

nextJs에 대핸 더욱 공부가 필요한 것 같다 ^_^