ErrorBoundary를 활용한 에러 처리


ErrorBoundary를 활용한 에러 처리

공식문서에서 에러 처리는 class 형태로 작성되어있다. 하지만 hook을 이용할 때에는 사용하기가 불편하다. class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } static getDerivedStateFromError(error) { // 다음 렌더링에서 폴백 UI가 보이도록 상태를 업데이트 합니다. return { hasError: true }; } componentDidCatch(error, errorInfo) { // 에러 리포팅 서비스에 에러를 기록할 수도 있습니다. logErrorToMyService(error, errorInfo); } render() { if (this.state.hasError) { // 폴백 UI를 커스텀하여 렌더링할 수 있습니다. return <h1>Something went wrong.</h...


#ErrorBoundary #react #reactErrorBoundary #reactQuery #suspense #typescript #타입스크립트

원문링크 : ErrorBoundary를 활용한 에러 처리