Skip to content

Commit 78c5129

Browse files
summerdevahg-pyun
andauthored
Translate: forwardRef (#727)
* Translate: forwardRef * fix: feedback from code review --------- Co-authored-by: Haegul Pyun <[email protected]>
1 parent b3222f1 commit 78c5129

File tree

1 file changed

+47
-47
lines changed

1 file changed

+47
-47
lines changed

src/content/reference/react/forwardRef.md

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: forwardRef
44

55
<Intro>
66

7-
`forwardRef` lets your component expose a DOM node to parent component with a [ref.](/learn/manipulating-the-dom-with-refs)
7+
`forwardRef` 를 사용하면 컴포넌트가 [ref.](/learn/manipulating-the-dom-with-refs)를 사용하여 부모 컴포넌트의 DOM 노드를 노출할 수 있습니다.
88

99
```js
1010
const SomeComponent = forwardRef(render)
@@ -16,11 +16,11 @@ const SomeComponent = forwardRef(render)
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## 레퍼런스 {/*reference*/}
2020

2121
### `forwardRef(render)` {/*forwardref*/}
2222

23-
Call `forwardRef()` to let your component receive a ref and forward it to a child component:
23+
컴포넌트가 ref를 받아 하위 컴포넌트로 전달하도록 하려면 `forwardRef()`를 호출하세요.
2424

2525
```js
2626
import { forwardRef } from 'react';
@@ -30,26 +30,26 @@ const MyInput = forwardRef(function MyInput(props, ref) {
3030
});
3131
```
3232

33-
[See more examples below.](#usage)
33+
[아래에서 더 많은 예시를 확인하세요.](#usage)
3434

35-
#### Parameters {/*parameters*/}
35+
#### 매개변수 {/*parameters*/}
3636

37-
* `render`: The render function for your component. React calls this function with the props and `ref` that your component received from its parent. The JSX you return will be the output of your component.
37+
* `render`: 컴포넌트의 렌더링 함수입니다. React는 컴포넌트가 부모로부터 받은 props와 `ref`로 이 함수를 호출합니다. 반환하는 JSX는 컴포넌트의 결과가 됩니다.
3838

39-
#### Returns {/*returns*/}
39+
#### 반환값 {/*returns*/}
4040

41-
`forwardRef` returns a React component that you can render in JSX. Unlike React components defined as plain functions, a component returned by `forwardRef` is also able to receive a `ref` prop.
41+
`forwardRef`는 JSX에서 렌더링할 수 있는 React 컴포넌트를 반환합니다. 일반 함수로 정의된 React 컴포넌트와 다르게, `forwardRef`가 반환하는 컴포넌트는 `ref` prop도 받을 수 있습니다.
4242

43-
#### Caveats {/*caveats*/}
43+
#### 주의 {/*caveats*/}
4444

45-
* In Strict Mode, React will **call your render function twice** in order to [help you find accidental impurities.](#my-initializer-or-updater-function-runs-twice) This is development-only behavior and does not affect production. If your render function is pure (as it should be), this should not affect the logic of your component. The result from one of the calls will be ignored.
45+
* Strict Mode에서 React는 [실수로 발생한 결함을 찾기 위해](#my-initializer-or-updater-function-runs-twice) **렌더링 함수를 두 번 호출**합니다. 이는 개발 환경 전용 동작이며 프로덕션 환경에는 영향을 미치지 않습니다. 렌더링 함수가 순수함수인 경우(그래야만 합니다.) 컴포넌트 로직에 영향을 미치지 않습니다. 호출 결과 중 하나의 결과는 무시됩니다.
4646

4747

4848
---
4949

50-
### `render` function {/*render-function*/}
50+
### `render` 함수 {/*render-function*/}
5151

52-
`forwardRef` accepts a render function as an argument. React calls this function with `props` and `ref`:
52+
`forwardRef`render 함수를 인수로 받습니다. React는 `props``ref`와 함께 이 함수를 호출합니다.
5353

5454
```js
5555
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -62,23 +62,23 @@ const MyInput = forwardRef(function MyInput(props, ref) {
6262
});
6363
```
6464

65-
#### Parameters {/*render-parameters*/}
65+
#### 매개변수 {/*render-parameters*/}
6666

67-
* `props`: The props passed by the parent component.
67+
* `props`: 부모 컴포넌트가 전달한 props입니다.
6868

69-
* `ref`: The `ref` attribute passed by the parent component. The `ref` can be an object or a function. If the parent component has not passed a ref, it will be `null`. You should either pass the `ref` you receive to another component, or pass it to [`useImperativeHandle`.](/reference/react/useImperativeHandle)
69+
* `ref`: 부모 컴포넌트가 전달한 `ref` 어트리뷰트입니다. `ref`는 객체나 함수일 수 있습니다. 부모 컴포넌트가 ref를 전달하지 않은 경우 `null`이 됩니다. 전달받은 `ref`를 다른 컴포넌트에 전달하거나 [`useImperativeHandle`.](/reference/react/useImperativeHandle)에 전달해야 합니다.
7070

71-
#### Returns {/*render-returns*/}
71+
#### 반환값 {/*render-returns*/}
7272

73-
`forwardRef` returns a React component that you can render in JSX. Unlike React components defined as plain functions, the component returned by `forwardRef` is able to take a `ref` prop.
73+
`forwardRef`는 JSX에서 렌더링할 수 있는 React 컴포넌트를 반환합니다. 일반 함수로 정의된 React 컴포넌트와 다르게 `forwardRef` 에 의해 반환되는 컴포넌트는 `ref` prop를 받을 수 있습니다.
7474

7575
---
7676

77-
## Usage {/*usage*/}
77+
## 사용법 {/*usage*/}
7878

79-
### Exposing a DOM node to the parent component {/*exposing-a-dom-node-to-the-parent-component*/}
79+
### 부모 컴포넌트에 DOM 노드 노출하기 {/*exposing-a-dom-node-to-the-parent-component*/}
8080

81-
By default, each component's DOM nodes are private. However, sometimes it's useful to expose a DOM node to the parent--for example, to allow focusing it. To opt in, wrap your component definition into `forwardRef()`:
81+
기본적으로 각 컴포넌트의 DOM 노드는 비공개입니다. 그러나 때로는 부모에 DOM 노드를 노출하는 것이 유용할 수 있습니다. 예를 들어 focus 하기 위해 노출할 수 있습니다. 이를 위해 컴포넌트 정의를 `forwardRef()`로 감싸주면 됩니다.
8282

8383
```js {3,11}
8484
import { forwardRef } from 'react';
@@ -94,7 +94,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
9494
});
9595
```
9696

97-
You will receive a <CodeStep step={1}>ref</CodeStep> as the second argument after props. Pass it to the DOM node that you want to expose:
97+
props 다음에 두 번째 인수로 <CodeStep step={1}>ref</CodeStep>를 받게 됩니다. 노출하려는 DOM 노드에 이를 전달합니다.
9898

9999
```js {8} [[1, 3, "ref"], [1, 8, "ref", 30]]
100100
import { forwardRef } from 'react';
@@ -110,7 +110,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
110110
});
111111
```
112112

113-
This lets the parent `Form` component access the <CodeStep step={2}>`<input>` DOM node</CodeStep> exposed by `MyInput`:
113+
이렇게 하면 부모인 `Form` 컴포넌트가 `MyInput`에 의해 노출된 <CodeStep step={2}>`<input>` DOM 노드</CodeStep>에 접근할 수 있습니다.
114114

115115
```js [[1, 2, "ref"], [1, 10, "ref", 41], [2, 5, "ref.current"]]
116116
function Form() {
@@ -131,15 +131,15 @@ function Form() {
131131
}
132132
```
133133

134-
This `Form` component [passes a ref](/reference/react/useRef#manipulating-the-dom-with-a-ref) to `MyInput`. The `MyInput` component *forwards* that ref to the `<input>` browser tag. As a result, the `Form` component can access that `<input>` DOM node and call [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus) on it.
134+
`Form` 컴포넌트는 `MyInput` 에게 [ref를 전달](/reference/react/useRef#manipulating-the-dom-with-a-ref)합니다. `MyInput` 컴포넌트는 해당 ref를 `<input>` 태그에 전달합니다. 결과적으로 `Form` 컴포넌트는 해당 `<input>` DOM 노드에 접근하여 [`focus()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus)를 호출할 수 있습니다.
135135

136-
Keep in mind that exposing a ref to the DOM node inside your component makes it harder to change your component's internals later. You will typically expose DOM nodes from reusable low-level components like buttons or text inputs, but you won't do it for application-level components like an avatar or a comment.
136+
컴포넌트 내부의 DOM 노드의 ref를 노출하면 나중에 컴포넌트의 내부를 변경하기가 더 어려워진다는 점에 유의하세요. 일반적으로 버튼이나 텍스트 input과 같이 재사용할 수 있는 저수준 컴포넌트에서 DOM 노드를 노출하지만, 아바타나 댓글 같은 애플리케이션 레벨의 컴포넌트에서는 노출하고 싶지 않을 것입니다.
137137

138-
<Recipes titleText="Examples of forwarding a ref">
138+
<Recipes title="ref 전달 예시">
139139

140-
#### Focusing a text input {/*focusing-a-text-input*/}
140+
#### 텍스트 input에 초점 맞추기 {/*focusing-a-text-input*/}
141141

142-
Clicking the button will focus the input. The `Form` component defines a ref and passes it to the `MyInput` component. The `MyInput` component forwards that ref to the browser `<input>`. This lets the `Form` component focus the `<input>`.
142+
버튼을 클릭하면 input에 포커스 됩니다. `Form` 컴포넌트는 ref를 정의하고 이를 `MyInput` 컴포넌트로 전달합니다. `MyInput` 컴포넌트는 해당 ref를 `input`으로 전달합니다. 이렇게 하면 `Form` 컴포넌트가 `input`의 포커스를 줄 수 있습니다.
143143

144144
<Sandpack>
145145

@@ -191,9 +191,9 @@ input {
191191

192192
<Solution />
193193

194-
#### Playing and pausing a video {/*playing-and-pausing-a-video*/}
194+
#### 비디오 재생 및 정지하기 {/*playing-and-pausing-a-video*/}
195195

196-
Clicking the button will call [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) and [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause) on a `<video>` DOM node. The `App` component defines a ref and passes it to the `MyVideoPlayer` component. The `MyVideoPlayer` component forwards that ref to the browser `<video>` node. This lets the `App` component play and pause the `<video>`.
196+
버튼을 클릭하면 `<video>` DOM 노드에서 [`play()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) [`pause()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/pause)를 호출합니다. `App` 컴포넌트는 ref를 정의하고 이를 `MyVideoPlayer` 컴포넌트에 전달합니다. `MyVideoPlayer` 컴포넌트는 해당 ref를 브라우저 `<video>` 노드로 전달합니다. 이렇게 하면 `App` 컴포넌트가 `<video>`를 재생하고 정지할 수 있습니다.
197197

198198
<Sandpack>
199199

@@ -252,9 +252,9 @@ button { margin-bottom: 10px; margin-right: 10px; }
252252

253253
---
254254

255-
### Forwarding a ref through multiple components {/*forwarding-a-ref-through-multiple-components*/}
255+
### 여러 컴포넌트를 통해 ref 전달하기 {/*forwarding-a-ref-through-multiple-components*/}
256256

257-
Instead of forwarding a `ref` to a DOM node, you can forward it to your own component like `MyInput`:
257+
`ref`DOM 노드로 전달하지 않고 `MyInput`과 같은 컴포넌트로 전달할 수 있습니다.
258258

259259
```js {1,5}
260260
const FormField = forwardRef(function FormField(props, ref) {
@@ -268,7 +268,7 @@ const FormField = forwardRef(function FormField(props, ref) {
268268
});
269269
```
270270

271-
If that `MyInput` component forwards a ref to its `<input>`, a ref to `FormField` will give you that `<input>`:
271+
`MyInput` 컴포넌트가 `<input>`에 ref를 전달하면 `FormField`의 ref는 해당 `<input>`을 얻을 수 있습니다.
272272

273273
```js {2,5,10}
274274
function Form() {
@@ -289,7 +289,7 @@ function Form() {
289289
}
290290
```
291291

292-
The `Form` component defines a ref and passes it to `FormField`. The `FormField` component forwards that ref to `MyInput`, which forwards it to a browser `<input>` DOM node. This is how `Form` accesses that DOM node.
292+
`Form` 컴포넌트는 ref를 정의하고 이를 `FormField`에 전달합니다. `FormField` 컴포넌트는 해당 ref를 `MyInput`으로 전달하고, 이 컴포넌트는 `<input>` DOM 노드로 전달합니다. 이것이 `Form``<input>` DOM 노드에 접근하는 방식입니다.
293293

294294

295295
<Sandpack>
@@ -367,9 +367,9 @@ input, button {
367367

368368
---
369369

370-
### Exposing an imperative handle instead of a DOM node {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
370+
### DOM 노드 대신 명령형 핸들 노출하기 {/*exposing-an-imperative-handle-instead-of-a-dom-node*/}
371371

372-
Instead of exposing an entire DOM node, you can expose a custom object, called an *imperative handle,* with a more constrained set of methods. To do this, you'd need to define a separate ref to hold the DOM node:
372+
전체 DOM 노드를 노출하는 대신 제한된 메서드 집합과 함께 *명령형 핸들*이라고 하는 사용자 정의 객체를 노출할 수 있습니다. 이를 위해 DOM 노드를 보유할 별도의 ref를 정의해야 합니다.
373373

374374
```js {2,6}
375375
const MyInput = forwardRef(function MyInput(props, ref) {
@@ -381,7 +381,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
381381
});
382382
```
383383

384-
Pass the `ref` you received to [`useImperativeHandle`](/reference/react/useImperativeHandle) and specify the value you want to expose to the `ref`:
384+
전달받은 `ref`[`useImperativeHandle`](/reference/react/useImperativeHandle)에 전달하고 노출하려는 값을 `ref`에 지정합니다.
385385

386386
```js {6-15}
387387
import { forwardRef, useRef, useImperativeHandle } from 'react';
@@ -404,7 +404,7 @@ const MyInput = forwardRef(function MyInput(props, ref) {
404404
});
405405
```
406406

407-
If some component gets a ref to `MyInput`, it will only receive your `{ focus, scrollIntoView }` object instead of the DOM node. This lets you limit the information you expose about your DOM node to the minimum.
407+
일부 컴포넌트가 `MyInput`의 ref를 받으면 DOM 노드 대신 `{ focus, scrollIntoView }` 객체만 받습니다. 이를 통해 노출하는 DOM 노드의 정보를 최소한으로 제한할 수 있습니다.
408408

409409
<Sandpack>
410410

@@ -463,25 +463,25 @@ input {
463463

464464
</Sandpack>
465465

466-
[Read more about using imperative handles.](/reference/react/useImperativeHandle)
466+
[명령형 핸들 사용에 대해 자세히 알아보세요.](/reference/react/useImperativeHandle)
467467

468468
<Pitfall>
469469

470-
**Do not overuse refs.** You should only use refs for *imperative* behaviors that you can't express as props: for example, scrolling to a node, focusing a node, triggering an animation, selecting text, and so on.
470+
**ref를 과도하게 사용하지 마세요.** 노드로 스크롤 하기, 노드에 포커스하기, 애니메이션 트리거하기, 텍스트 선택하기 등 prop로 표현할 수 없는 필수적인 동작에만 ref를 사용해야 합니다.
471471

472-
**If you can express something as a prop, you should not use a ref.** For example, instead of exposing an imperative handle like `{ open, close }` from a `Modal` component, it is better to take `isOpen` as a prop like `<Modal isOpen={isOpen} />`. [Effects](/learn/synchronizing-with-effects) can help you expose imperative behaviors via props.
472+
**prop로 무언가를 표현할 수 있다면 ref를 사용해서는 안 됩니다.** 예를 들어 `Modal` 컴포넌트에서 `{ open, close }`와 같은 명령형 핸들을 노출하는 대신 `<Modal isOpen={isOpen} />`과 같이 prop `isOpen`을 사용하는 것이 더 좋습니다. [Effects](/learn/synchronizing-with-effects)는 props를 통해 명령형 동작을 노출하는 데 도움이 될 수 있습니다.
473473

474474
</Pitfall>
475475

476476
---
477477

478-
## Troubleshooting {/*troubleshooting*/}
478+
## 문제해결 {/*troubleshooting*/}
479479

480-
### My component is wrapped in `forwardRef`, but the `ref` to it is always `null` {/*my-component-is-wrapped-in-forwardref-but-the-ref-to-it-is-always-null*/}
480+
### 컴포넌트가 `forwardRef`로 감싸져 있지만, 컴포넌트의 `ref`는 항상 `null`입니다. {/*my-component-is-wrapped-in-forwardref-but-the-ref-to-it-is-always-null*/}
481481

482-
This usually means that you forgot to actually use the `ref` that you received.
482+
일반적으로 `ref`를 실제로 사용하는 것을 잊어버렸다는 것입니다.
483483

484-
For example, this component doesn't do anything with its `ref`:
484+
예를 들어 이 컴포넌트는 `ref`로 아무것도 하지 않습니다.
485485

486486
```js {1}
487487
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -494,7 +494,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
494494
});
495495
```
496496

497-
To fix it, pass the `ref` down to a DOM node or another component that can accept a ref:
497+
이 문제를 해결하려면 `ref`DOM 노드나 ref를 받을 수 있는 다른 컴포넌트에 전달하세요.
498498

499499
```js {1,5}
500500
const MyInput = forwardRef(function MyInput({ label }, ref) {
@@ -507,7 +507,7 @@ const MyInput = forwardRef(function MyInput({ label }, ref) {
507507
});
508508
```
509509

510-
The `ref` to `MyInput` could also be `null` if some of the logic is conditional:
510+
일부 로직이 조건부인 경우 `MyInput``ref``null`일 수 있습니다.
511511

512512
```js {1,5}
513513
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
@@ -520,7 +520,7 @@ const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {
520520
});
521521
```
522522

523-
If `showInput` is `false`, then the ref won't be forwarded to any node, and a ref to `MyInput` will remain empty. This is particularly easy to miss if the condition is hidden inside another component, like `Panel` in this example:
523+
`showInput``false`이면 ref가 어떤 노드로도 전달되지 않으며 `MyInput`의 ref는 비어 있게 됩니다. 이 예제의 `Panel`과 같이 조건이 다른 컴포넌트 안에 숨겨져 있는 경우 특히 이 점을 놓치기 쉽습니다.
524524

525525
```js {5,7}
526526
const MyInput = forwardRef(function MyInput({ label, showInput }, ref) {

0 commit comments

Comments
 (0)