diff --git a/content/docs/error-boundaries.md b/content/docs/error-boundaries.md index d8ff0314b..b5373aa7e 100644 --- a/content/docs/error-boundaries.md +++ b/content/docs/error-boundaries.md @@ -1,28 +1,28 @@ --- id: error-boundaries -title: Error Boundaries +title: 에러 경계(Error Boundaries) permalink: docs/error-boundaries.html --- -In the past, JavaScript errors inside components used to corrupt React’s internal state and cause it to [emit](https://github.com/facebook/react/issues/4026) [cryptic](https://github.com/facebook/react/issues/6895) [errors](https://github.com/facebook/react/issues/8579) on next renders. These errors were always caused by an earlier error in the application code, but React did not provide a way to handle them gracefully in components, and could not recover from them. +과거에는 컴포넌트 내부의 자바스크립트 에러가 React의 내부 상태를 훼손하고 다음 렌더링에서 [암호화](https://github.com/facebook/react/issues/6895) [에러](https://github.com/facebook/react/issues/8579) [방출](https://github.com/facebook/react/issues/4026)을 유발하곤 했습니다. 이러한 에러는 항상 애플리케이션 코드의 이전 단계의 에러로 인해 발생했지만, React는 컴포넌트 내에서 에러를 정상적으로 처리할 수 있는 방법을 제공하지 않아 이를 복구할 수가 없었습니다. -## Introducing Error Boundaries {#introducing-error-boundaries} +## 에러 경계의 소개 {#introducing-error-boundaries} -A JavaScript error in a part of the UI shouldn’t break the whole app. To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. +UI의 일부분에 존재하는 자바스크립트 에러가 전체 애플리케이션을 중단시켜서는 안 됩니다. React 사용자들이 겪는 이 문제를 해결하기 위해 React 16에서는 에러 경계(“error boundary”)라는 새로운 개념이 도입되었습니다. -Error boundaries are React components that **catch JavaScript errors anywhere in their child component tree, log those errors, and display a fallback UI** instead of the component tree that crashed. Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them. +에러 경계는 **하위 컴포넌트 트리의 어디에서든 자바스크립트 에러를 기록하며 깨진 컴포넌트 트리 대신 폴백 UI를 보여주는** React 컴포넌트입니다. 에러 경계는 렌더링 도중 생명주기 메서드 및 그 아래에 있는 전체 트리에서 에러를 잡아냅니다. > Note > -> Error boundaries do **not** catch errors for: +> 에러 경계는 다음과 같은 에러는 포착하지 **않습니다**. > -> * Event handlers ([learn more](#how-about-event-handlers)) -> * Asynchronous code (e.g. `setTimeout` or `requestAnimationFrame` callbacks) -> * Server side rendering -> * Errors thrown in the error boundary itself (rather than its children) +> * 이벤트 핸들러 ([더 알아보기](#how-about-event-handlers)) +> * 비동기적 코드 (예: `setTimeout` 혹은 `requestAnimationFrame` 콜백) +> * 서버 사이드 렌더링 +> * 자식에서가 아닌 에러 경계 자체에서 발생하는 에러 -A class component becomes an error boundary if it defines either (or both) of the lifecycle methods [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) or [`componentDidCatch()`](/docs/react-component.html#componentdidcatch). Use `static getDerivedStateFromError()` to render a fallback UI after an error has been thrown. Use `componentDidCatch()` to log error information. +생명주기 메서드인 [`static getDerivedStateFromError()`](/docs/react-component.html#static-getderivedstatefromerror) 와 [`componentDidCatch()`](/docs/react-component.html#componentdidcatch) 중 하나 (혹은 둘 다)를 정의하면 클래스 컴포넌트 자체가 에러 경계가 됩니다. 에러가 발생한 뒤에 폴백 UI를 렌더링하려면 `static getDerivedStateFromError()`를 사용하세요. 에러 정보를 기록하려면 `componentDidCatch()`를 사용하세요. ```js{7-10,12-15,18-21} class ErrorBoundary extends React.Component { @@ -32,18 +32,18 @@ class ErrorBoundary extends React.Component { } static getDerivedStateFromError(error) { - // Update state so the next render will show the fallback UI. + // 다음 렌더링에서 폴백 UI가 보이도록 상태를 업데이트 합니다. return { hasError: true }; } componentDidCatch(error, errorInfo) { - // You can also log the error to an error reporting service + // 에러 리포팅 서비스에 에러를 기록할 수도 있습니다. logErrorToMyService(error, errorInfo); } render() { if (this.state.hasError) { - // You can render any custom fallback UI + // 폴백 UI를 커스텀하여 렌더링할 수 있습니다. return
+
-You can also see the filenames and line numbers in the component stack trace. This works by default in [Create React App](https://github.com/facebookincubator/create-react-app) projects:
+또한 컴포넌트 스택 추적 내에서 파일 이름과 줄 번호도 확인할 수 있습니다. 이는 [Create React App](https://github.com/facebookincubator/create-react-app) 프로젝트 내에서 기본적으로 동작합니다.
-
+
-If you don’t use Create React App, you can add [this plugin](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source) manually to your Babel configuration. Note that it’s intended only for development and **must be disabled in production**.
+Create React App을 사용하지 않는 경우에는 수동으로 [이 플러그인](https://www.npmjs.com/package/babel-plugin-transform-react-jsx-source)을 Babel 설정을 추가할 수 있습니다. 이 기능은 개발 단계를 위해서만 제작되었으며 **프로덕션 환경에서는 비활성화 해야합니다**.
-> Note
+> 주의
>
-> Component names displayed in the stack traces depend on the [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) property. If you support older browsers and devices which may not yet provide this natively (e.g. IE 11), consider including a `Function.name` polyfill in your bundled application, such as [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name). Alternatively, you may explicitly set the [`displayName`](/docs/react-component.html#displayname) property on all your components.
+> 스택 추적에 표시되는 컴포넌트 이름은 [`Function.name`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name) 프로퍼티에 따라 다릅니다. 아직 기본적으로 제공하지 않는 구형 브라우저 혹은 디바이스(예: IE11)를 지원하는 경우 번들 애플리케이션에 [`function.name-polyfill`](https://github.com/JamesMGreene/Function.name)과 같은 `Function.name` 폴리필(Polyfill)을 포함시키는 것을 고려해볼 수 있습니다. 또는 모든 컴포넌트에서[`displayName`](/docs/react-component.html#displayname) 프로퍼티를 명시적으로 설정할 수도 있습니다.
-## How About try/catch? {#how-about-trycatch}
+## try/catch는 어떤가요? {#how-about-trycatch}
-`try` / `catch` is great but it only works for imperative code:
+`try` / `catch`는 훌륭하지만 명령형 코드에서만 동작합니다.
```js
try {
@@ -116,21 +116,21 @@ try {
}
```
-However, React components are declarative and specify *what* should be rendered:
+그러나 React 컴포넌트는 선언적이며 *무엇*을 렌더링할지 구체화합니다.
```js
```
-Error boundaries preserve the declarative nature of React, and behave as you would expect. For example, even if an error occurs in a `componentDidUpdate` method caused by a `setState` somewhere deep in the tree, it will still correctly propagate to the closest error boundary.
+에러 경계는 React의 선언적인 특성을 보존하고 예상한 대로 동작합니다. 예를 들어 트리의 깊숙한 어딘가에 있는`setState`에 의해 유발된 `componentDidUpdate` 메서드에서 에러가 발생하더라도 가장 가까운 에러 경계에 올바르게 전달됩니다.
-## How About Event Handlers? {#how-about-event-handlers}
+## 이벤트 핸들러는 어떤가요? {#how-about-event-handlers}
-Error boundaries **do not** catch errors inside event handlers.
+에러 경계는 이벤트 핸들러 내부에서는 에러를 포착하지 **않습니다**.
-React doesn't need error boundaries to recover from errors in event handlers. Unlike the render method and lifecycle methods, the event handlers don't happen during rendering. So if they throw, React still knows what to display on the screen.
+React는 이벤트 핸들러의 에러를 해결하기 위해서 에러 경계를 필요로 하지 않습니다. render 메서드 및 생명주기 메서드와 달리 이벤트 핸들러는 렌더링 중에 발생하지 않습니다. 따라서 이벤트 핸들러가 에러를 던져도 React는 여전히 화면에 무엇을 표시해야 할 지 알고 있습니다.
-If you need to catch an error inside event handler, use the regular JavaScript `try` / `catch` statement:
+이벤트 핸들러 내에서 에러를 잡아야 하는 경우에 일반 자바스크립트의 `try` / `catch` 구문을 사용하세요.
```js{9-13,17-20}
class MyComponent extends React.Component {
@@ -142,7 +142,7 @@ class MyComponent extends React.Component {
handleClick() {
try {
- // Do something that could throw
+ // 에러를 던질 수 있는 무언가를 해야합니다.
} catch (error) {
this.setState({ error });
}
@@ -157,10 +157,10 @@ class MyComponent extends React.Component {
}
```
-Note that the above example is demonstrating regular JavaScript behavior and doesn't use error boundaries.
+위의 예시는 일반적인 자바스크립트의 동작을 보여주며 에러 경계를 사용하지 않습니다.
-## Naming Changes from React 15 {#naming-changes-from-react-15}
+## React 15에서 변경된 명명법 {#naming-changes-from-react-15}
-React 15 included a very limited support for error boundaries under a different method name: `unstable_handleError`. This method no longer works, and you will need to change it to `componentDidCatch` in your code starting from the first 16 beta release.
+React 15는 `unstable_handleError`라는 다른 메서드 이름으로 에러 경계에 대해 매우 제한적인 지원을 포함하고 있었습니다. 이 메서드는 더 이상 동작하지 않으며 첫 16 베타 릴리즈부터 코드에서 `componentDidCatch`로 변경해야 합니다.
-For this change, we’ve provided a [codemod](https://github.com/reactjs/react-codemod#error-boundaries) to automatically migrate your code.
+이 변경사항을 위해 코드를 자동으로 마이그레이션하기 위한 [codemod](https://github.com/reactjs/react-codemod#error-boundaries)를 제공했습니다.