diff --git a/src/content/blog/2024/04/25/react-19-upgrade-guide.md b/src/content/blog/2024/04/25/react-19-upgrade-guide.md index bbbc2fe88..9aabf178f 100644 --- a/src/content/blog/2024/04/25/react-19-upgrade-guide.md +++ b/src/content/blog/2024/04/25/react-19-upgrade-guide.md @@ -1,8 +1,8 @@ --- -title: "React 19 Upgrade Guide" +title: "React 19 업그레이드 가이드" author: Ricky Hanlon date: 2024/04/25 -description: The improvements added to React 19 require some breaking changes, but we've worked to make the upgrade as smooth as possible and we don't expect the changes to impact most apps. In this post, we will guide you through the steps for upgrading apps and libraries to React 19. +description: React 19에 추가된 개선 사항들로 인해 일부 파괴적 변경(breaking changes)이 필요하지만, 저희는 가능한 한 업그레이드가 원활하게 이루어지도록 노력했으며 대부분의 앱에 큰 영향을 미치지 않을 것으로 예상합니다. 이 게시물에서는 앱과 라이브러리를 React 19로 업그레이드하는 단계를 안내해 드리겠습니다. --- April 25, 2024 by [Ricky Hanlon](https://twitter.com/rickhanlonii) @@ -12,44 +12,44 @@ April 25, 2024 by [Ricky Hanlon](https://twitter.com/rickhanlonii) -The improvements added to React 19 require some breaking changes, but we've worked to make the upgrade as smooth as possible, and we don't expect the changes to impact most apps. +React 19에 추가된 개선 사항들로 인해 일부 파괴적 변경(breaking changes)이 필요하지만, 저희는 가능한 한 업그레이드가 원활하게 이루어지도록 노력했으며 대부분의 앱에 큰 영향을 미치지 않을 것으로 예상합니다. 이 게시물에서는 앱과 라이브러리를 React 19로 업그레이드하는 단계를 안내해 드리겠습니다. -#### React 18.3 has also been published {/*react-18-3*/} +#### React 18.3 또한 출시되었습니다. {/*react-18-3*/} -To help make the upgrade to React 19 easier, we've published a `react@18.3` release that is identical to 18.2 but adds warnings for deprecated APIs and other changes that are needed for React 19. +React 19로의 업그레이드를 더 쉽게 돕기 위해, 저희는 **react@18.3**을 출시했습니다. 이 버전은 18.2와 동일하지만, 더 이상 사용되지 않는 API 및 React 19에 필요한 변경 사항에 대한 경고를 추가했습니다. -We recommend upgrading to React 18.3 first to help identify any issues before upgrading to React 19. +React 19로 업그레이드하기 전에 먼저 React 18.3으로 업데이트하여 잠재적인 문제를 미리 파악하는 것을 권장합니다. -For a list of changes in 18.3 see the [Release Notes](https://github.com/facebook/react/blob/main/CHANGELOG.md#1830-april-25-2024). +18.3 버전의 변경 사항 목록은 [릴리스 노트](https://github.com/facebook/react/blob/main/CHANGELOG.md#1830-april-25-2024)에서 확인하실 수 있습니다. -In this post, we will guide you through the steps for upgrading to React 19: +이 게시물에서는 React 19로 업그레이드하는 단계를 안내해 드립니다: -- [Installing](#installing) -- [Codemods](#codemods) -- [Breaking changes](#breaking-changes) -- [New deprecations](#new-deprecations) -- [Notable changes](#notable-changes) -- [TypeScript changes](#typescript-changes) -- [Changelog](#changelog) +- [설치](#installing) +- [코드모드](#codemods) +- [주요 변경 사항](#breaking-changes) +- [새로 사용 중단된 사항](#new-deprecations) +- [주목할 만한 변경 사항](#notable-changes) +- [TypeScript 변경 사항](#typescript-changes) +- [변경 로그](#changelog) -If you'd like to help us test React 19, follow the steps in this upgrade guide and [report any issues](https://github.com/facebook/react/issues/new?assignees=&labels=React+19&projects=&template=19.md&title=%5BReact+19%5D) you encounter. For a list of new features added to React 19, see the [React 19 release post](/blog/2024/12/05/react-19). +React 19을 테스트해보고 싶으시다면, 이 업그레이드 가이드에 나와 있는 단계를 따라주시고, 문제가 발생하면 [이슈를 제보해주세요](https://github.com/facebook/react/issues/new?assignees=&labels=React+19&projects=&template=19.md&title=%5BReact+19%5D). React 19에 추가된 새로운 기능 목록은 [React 19 릴리스 게시글](/blog/2024/12/05/react-19)에서 확인하실 수 있습니다. --- -## Installing {/*installing*/} +## 설치 {/*installing*/} -#### New JSX Transform is now required {/*new-jsx-transform-is-now-required*/} +#### 이제 새로운 JSX 변환 방식이 필수입니다. {/*new-jsx-transform-is-now-required*/} -We introduced a [new JSX transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) in 2020 to improve bundle size and use JSX without importing React. In React 19, we're adding additional improvements like using ref as a prop and JSX speed improvements that require the new transform. +우리는 2020년에 [새로운 JSX 변환](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)을 도입하여 번들 크기를 줄이고 React를 import하지 않고도 JSX를 사용할 수 있도록 했습니다. React 19에서는 ref를 prop으로 사용할 수 있는 기능이나 JSX 성능 향상과 같은 추가적인 개선 사항이 도입되며, 이러한 기능들은 새로운 변환(new transform)을 필요로 합니다. -If the new transform is not enabled, you will see this warning: +새로운 변환이 활성화되지 않은 경우, 다음과 같은 경고가 표시됩니다: @@ -62,79 +62,77 @@ Your app (or one of its dependencies) is using an outdated JSX transform. Update -We expect most apps will not be affected since the transform is enabled in most environments already. For manual instructions on how to upgrade, please see the [announcement post](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html). +대부분의 환경에서는 이미 새로운 변환이 활성화되어 있기 때문에 대부분의 앱은 영향을 받지 않을 것으로 예상됩니다. 수동으로 업그레이드하는 방법에 대한 안내는 [공지 게시글](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)을 참조해주세요. -To install the latest version of React and React DOM: - +최신 버전의 React 및 React DOM을 설치하려면: ```bash npm install --save-exact react@^19.0.0 react-dom@^19.0.0 ``` -Or, if you're using Yarn: - +또는 Yarn을 사용하는 경우: ```bash yarn add --exact react@^19.0.0 react-dom@^19.0.0 ``` -If you're using TypeScript, you also need to update the types. +TypeScript를 사용하는 경우, 타입 정의도 함께 업데이트해야 합니다. ```bash npm install --save-exact @types/react@^19.0.0 @types/react-dom@^19.0.0 ``` -Or, if you're using Yarn: +또는 Yarn을 사용하는 경우: ```bash yarn add --exact @types/react@^19.0.0 @types/react-dom@^19.0.0 ``` -We're also including a codemod for the most common replacements. See [TypeScript changes](#typescript-changes) below. +가장 일반적인 변경 사항들을 위한 codemod도 포함되어 있습니다. 아래의 [TypeScript 변경 사항](#typescript-changes)을 참고하세요. -## Codemods {/*codemods*/} +## 코드모드 {/*codemods*/} -To help with the upgrade, we've worked with the team at [codemod.com](https://codemod.com) to publish codemods that will automatically update your code to many of the new APIs and patterns in React 19. +업그레이드를 돕기 위해, 우리는 [codemod.com](https://codemod.com) 팀과 협력하여 React 19의 새로운 API와 패턴들로 코드를 자동으로 업데이트해주는 codemod들을 공개했습니다. -All codemods are available in the [`react-codemod` repo](https://github.com/reactjs/react-codemod) and the Codemod team have joined in helping maintain the codemods. To run these codemods, we recommend using the `codemod` command instead of the `react-codemod` because it runs faster, handles more complex code migrations, and provides better support for TypeScript. +모든 codemod는 [`react-codemod` 저장소](https://github.com/reactjs/react-codemod) 에 있으며, Codemod 팀도 이 codemod들을 유지보수하는 데 함께하고 있습니다. 이러한 codemod들을 실행할 때는`eact-codemod` 보다 `codemod` 명령어를 사용하는 것을 권장합니다. codemod는 더 빠르게 실행되며, 더 복잡한 코드 마이그레이션을 처리하고, TypeScript에 대한 더 나은 지원을 제공합니다. -#### Run all React 19 codemods {/*run-all-react-19-codemods*/} +#### React 19 codemod 전체 실행 {/*run-all-react-19-codemods*/} -Run all codemods listed in this guide with the React 19 `codemod` recipe: +이 가이드에 나열된 모든 codemod를 React 19의 `codemod` 레시피를 통해 한 번에 실행하려면:: ```bash npx codemod@latest react/19/migration-recipe ``` -This will run the following codemods from `react-codemod`: +이 명령어는 `react-codemod`의 다음 codemod들을 실행합니다: - [`replace-reactdom-render`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-reactdom-render) - [`replace-string-ref`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-string-ref) - [`replace-act-import`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-act-import) - [`replace-use-form-state`](https://github.com/reactjs/react-codemod?tab=readme-ov-file#replace-use-form-state) - [`prop-types-typescript`](https://github.com/reactjs/react-codemod#react-proptypes-to-prop-types) -This does not include the TypeScript changes. See [TypeScript changes](#typescript-changes) below. +이 명령어는 TypeScript 변경 사항은 포함하지 않습니다. 아래의 [TypeScript changes](#typescript-changes) 을 참고하세요. -Changes that include a codemod include the command below. +Codemod이 포함된 변경 사항에는 아래와 같이 명령어가 함께 제공됩니다. -For a list of all available codemods, see the [`react-codemod` repo](https://github.com/reactjs/react-codemod). +사용 가능한 모든 codemod 목록은 [`react-codemod` 저장소](https://github.com/reactjs/react-codemod)를 참고하세요. -## Breaking changes {/*breaking-changes*/} +## 주요 변경사항 {/*breaking-changes*/} -### Errors in render are not re-thrown {/*errors-in-render-are-not-re-thrown*/} +### 렌더 중 발생한 오류는 re-throw 하지 않음{/*errors-in-render-are-not-re-thrown*/} -In previous versions of React, errors thrown during render were caught and rethrown. In DEV, we would also log to `console.error`, resulting in duplicate error logs. +이전 버전의 React에서는 렌더링 중 발생한 오류를 잡아서 다시 throw 했습니다. DEV 환경에서는 `console.error`로도 로그를 출력하여 오류 로그가 중복되는 문제가 있었습니다. -In React 19, we've [improved how errors are handled](/blog/2024/04/25/react-19#error-handling) to reduce duplication by not re-throwing: +React 19에서는 [오류 처리 방식이 개선되었습니다.](/blog/2024/04/25/react-19#error-handling) 더 이상 오류를 re-throw 하지 않아 중복 로그가 줄어듭니다: -- **Uncaught Errors**: Errors that are not caught by an Error Boundary are reported to `window.reportError`. -- **Caught Errors**: Errors that are caught by an Error Boundary are reported to `console.error`. +- **처리되지 않은 오류**: Error Boundary에서 잡히지 않은 오류는 `window.reportError`로 보고됩니다. +- **처리된 오류**: Error Boundary에서 잡힌 오류는 `console.error`로 보고됩니다. -This change should not impact most apps, but if your production error reporting relies on errors being re-thrown, you may need to update your error handling. To support this, we've added new methods to `createRoot` and `hydrateRoot` for custom error handling: +이 변경은 대부분의 앱에 영향을 주지 않지만, 프로덕션 오류 리포팅이 오류의 재-throw에 의존하고 있다면, 오류 처리 방식을 업데이트해야 할 수 있습니다. 이를 지원하기 위해 `createRoot` 및 `hydrateRoot` 에 사용자 정의 오류 처리를 위한 새로운 메서드가 추가되었습니다: ```js [[1, 2, "onUncaughtError"], [2, 5, "onCaughtError"]] const root = createRoot(container, { @@ -147,20 +145,20 @@ const root = createRoot(container, { }); ``` -For more info, see the docs for [`createRoot`](https://react.dev/reference/react-dom/client/createRoot) and [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot). +자세한 내용은 [`createRoot`](https://react.dev/reference/react-dom/client/createRoot) 및 [`hydrateRoot`](https://react.dev/reference/react-dom/client/hydrateRoot) 문서를 참고하세요. -### Removed deprecated React APIs {/*removed-deprecated-react-apis*/} +### React의 더 이상 사용되지 않는 API 제거 {/*removed-deprecated-react-apis*/} -#### Removed: `propTypes` and `defaultProps` for functions {/*removed-proptypes-and-defaultprops*/} -`PropTypes` were deprecated in [April 2017 (v15.5.0)](https://legacy.reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings). +#### 제거됨: 함수형 컴포넌트에서의 `propTypes` 및 `defaultProps` {/*removed-proptypes-and-defaultprops*/} +`PropTypes`는 [2017년 4월 (v15.5.0)](https://legacy.reactjs.org/blog/2017/04/07/react-v15.5.0.html#new-deprecation-warnings) 부터 더 이상 권장하지 않습니다. -In React 19, we're removing the `propType` checks from the React package, and using them will be silently ignored. If you're using `propTypes`, we recommend migrating to TypeScript or another type-checking solution. +React 19에서는 `propType` 검사 기능이 React 패키지에서 제거되며, 사용하더라도 아무 동작도 하지 않습니다. `propTypes`를 사용 중이라면 TypeScript나 다른 타입 검사 도구로 마이그레이션하는 것을 권장합니다. -We're also removing `defaultProps` from function components in place of ES6 default parameters. Class components will continue to support `defaultProps` since there is no ES6 alternative. +또한, 함수형 컴포넌트에서는 `defaultProps` 가 제거되며, 대신 **ES6의 기본 매개변수(default parameters)**를 사용해야 합니다. 클래스형 컴포넌트에서는 `defaultProps` 가 여전히 지원됩니다 (ES6 대안이 없기 때문입니다). ```js -// Before +// 변경 전 import PropTypes from 'prop-types'; function Heading({text}) { @@ -174,7 +172,7 @@ Heading.defaultProps = { }; ``` ```ts -// After +// 변경 후 interface Props { text?: string; } @@ -185,7 +183,7 @@ function Heading({text = 'Hello, world!'}: Props) { -Codemod `propTypes` to TypeScript with: +Codemod을 사용해 `propTypes` 를 TypeScript로 변환하려면 다음 명령어를 실행하세요: ```bash npx codemod@latest react/prop-types-typescript @@ -193,16 +191,16 @@ npx codemod@latest react/prop-types-typescript -#### Removed: Legacy Context using `contextTypes` and `getChildContext` {/*removed-removing-legacy-context*/} +#### 제거됨: `contextTypes` 와 `getChildContext`를 사용하는 레거시 컨텍스트 {/*removed-removing-legacy-context*/} -Legacy Context was deprecated in [October 2018 (v16.6.0)](https://legacy.reactjs.org/blog/2018/10/23/react-v-16-6.html). +레거시 컨텍스트는 [2018년 10월 (v16.6.0)](https://legacy.reactjs.org/blog/2018/10/23/react-v-16-6.html)부터 더 이상 권장되지 않습니다. -Legacy Context was only available in class components using the APIs `contextTypes` and `getChildContext`, and was replaced with `contextType` due to subtle bugs that were easy to miss. In React 19, we're removing Legacy Context to make React slightly smaller and faster. +레거시 컨텍스트는 클래스형 컴포넌트에서 `contextTypes` 와 `getChildContext` API를 통해 사용 가능했지만, 미묘한 버그들로 인해 `contextType` API로 대체되었습니다. React 19에서는 React의 크기를 줄이고 성능을 향상시키기 위해 레거시 컨텍스트가 제거됩니다. -If you're still using Legacy Context in class components, you'll need to migrate to the new `contextType` API: +아직도 클래스형 컴포넌트에서 레거시 컨텍스트를 사용하고 있다면, 새로운 `contextType`API로 마이그레이션해야 합니다: ```js {5-11,19-21} -// Before +// 변경 전 import PropTypes from 'prop-types'; class Parent extends React.Component { @@ -231,7 +229,7 @@ class Child extends React.Component { ``` ```js {2,7,9,15} -// After +// 변경 후 const FooContext = React.createContext(); class Parent extends React.Component { @@ -253,15 +251,15 @@ class Child extends React.Component { } ``` -#### Removed: string refs {/*removed-string-refs*/} -String refs were deprecated in [March, 2018 (v16.3.0)](https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html). +#### 제거됨: 문자열 refs {/*removed-string-refs*/} +문자열 refs는 [2018년 3월 (v16.3.0)](https://legacy.reactjs.org/blog/2018/03/27/update-on-async-rendering.html)부터 더이상 권장되지 않습니다. -Class components supported string refs before being replaced by ref callbacks due to [multiple downsides](https://github.com/facebook/react/issues/1373). In React 19, we're removing string refs to make React simpler and easier to understand. +클래스형 컴포넌트에서는 문자열 refs를 사용할 수 있었지만, [여러 단점들](https://github.com/facebook/react/issues/1373)로 인해 ref 콜백 방식으로 대체되었습니다. React 19에서는 React를 더 간단하고 이해하기 쉽게 만들기 위해 문자열 refs가 제거됩니다. -If you're still using string refs in class components, you'll need to migrate to ref callbacks: +클래스형 컴포넌트에서 아직 문자열 refs를 사용하고 있다면, ref 콜백으로 마이그레이션해야 합니다: ```js {4,8} -// Before +// 변경 전 class MyComponent extends React.Component { componentDidMount() { this.refs.input.focus(); @@ -274,7 +272,7 @@ class MyComponent extends React.Component { ``` ```js {4,8} -// After +// 변경 후 class MyComponent extends React.Component { componentDidMount() { this.input.focus(); @@ -288,7 +286,7 @@ class MyComponent extends React.Component { -Codemod string refs with `ref` callbacks: +Codemod을 사용해 문자열 refs를 `ref` 콜백으로 변환하려면: ```bash npx codemod@latest react/19/replace-string-ref @@ -296,45 +294,45 @@ npx codemod@latest react/19/replace-string-ref -#### Removed: Module pattern factories {/*removed-module-pattern-factories*/} -Module pattern factories were deprecated in [August 2019 (v16.9.0)](https://legacy.reactjs.org/blog/2019/08/08/react-v16.9.0.html#deprecating-module-pattern-factories). +#### 제거됨: 모듈 패턴 팩토리 {/*removed-module-pattern-factories*/} +모듈 패턴 팩토리는 [2019년 8월 (v16.9.0)](https://legacy.reactjs.org/blog/2019/08/08/react-v16.9.0.html#deprecating-module-pattern-factories)부터 더이상 권장되지 않습니다. -This pattern was rarely used and supporting it causes React to be slightly larger and slower than necessary. In React 19, we're removing support for module pattern factories, and you'll need to migrate to regular functions: +이 패턴은 거의 사용되지 않았으며, 이를 지원하는 것은 React를 불필요하게 더 크고 느리게 만들었습니다. React 19에서는 모듈 패턴 팩토리에 대한 지원이 제거되며, 일반 함수로 마이그레이션해야 합니다: ```js -// Before +// 변경 전 function FactoryComponent() { return { render() { return
; } } } ``` ```js -// After +// 변경 후 function FactoryComponent() { return
; } ``` -#### Removed: `React.createFactory` {/*removed-createfactory*/} -`createFactory` was deprecated in [February 2020 (v16.13.0)](https://legacy.reactjs.org/blog/2020/02/26/react-v16.13.0.html#deprecating-createfactory). +#### 제거됨: `React.createFactory` {/*removed-createfactory*/} +`createFactory` 는 [2020년 2월 (v16.13.0)](https://legacy.reactjs.org/blog/2020/02/26/react-v16.13.0.html#deprecating-createfactory)부터 더이상 권장되지 않습니다. -Using `createFactory` was common before broad support for JSX, but it's rarely used today and can be replaced with JSX. In React 19, we're removing `createFactory` and you'll need to migrate to JSX: +`createFactory` 는 JSX가 널리 사용되기 전에는 일반적이었지만, 오늘날에는 거의 사용되지 않으며 JSX로 쉽게 대체할 수 있습니다. React 19에서는 `createFactory` 가 제거되며, JSX로 마이그레이션해야 합니다: ```js -// Before +// 변경 전 import { createFactory } from 'react'; const button = createFactory('button'); ``` ```js -// After +// 변경 후 const button =