You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/learn/manipulating-the-dom-with-refs.md
+6-105Lines changed: 6 additions & 105 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -318,31 +318,6 @@ li {
318
318
key={cat.id}
319
319
ref={node=> {
320
320
constmap=getMap();
321
-
<<<<<<<HEAD
322
-
if (node) {
323
-
// Map에 노드를 추가합니다
324
-
map.set(cat, node);
325
-
} else {
326
-
// Map에서 노드를 제거합니다
327
-
map.delete(cat);
328
-
}
329
-
}}
330
-
>
331
-
```
332
-
333
-
위 방법으로 이후 Map에서 개별적인 DOM 노드를 읽을 수 있습니다.
334
-
335
-
<Canary>
336
-
337
-
This example shows another approach for managing the Map with a `ref` callback cleanup function.
338
-
339
-
```js
340
-
<li
341
-
key={cat.id}
342
-
ref={node=> {
343
-
constmap=getMap();
344
-
=======
345
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
346
321
// Add to the Map
347
322
map.set(cat, node);
348
323
@@ -368,11 +343,10 @@ Read more about [how this helps find bugs](/reference/react/StrictMode#fixing-bu
368
343
369
344
## 다른 컴포넌트의 DOM 노드 접근하기 {/*accessing-another-components-dom-nodes*/}
370
345
371
-
<<<<<<< HEAD
372
346
`<input />`같은 브라우저 요소를 출력하는 내장 컴포넌트에 ref를 주입할 때 React는 ref의 `current` 프로퍼티를 그에 해당하는 (브라우저의 실제 `<input />` 같은) DOM 노드로 설정합니다.
373
347
374
348
하지만 `<MyInput />` 같이 **직접 만든** 컴포넌트에 ref를 주입할 때는 `null`이 기본적으로 주어집니다. 여기 앞서 말한 내용을 설명하는 예시가 있습니다. 버튼을 클릭할 때 input 요소에 포커스 **되지 않는 것을** 주목하세요.
375
-
=======
349
+
376
350
<Pitfall>
377
351
Refs are an escape hatch. Manually manipulating _another_ component's DOM nodes can make your code fragile.
378
352
</Pitfall>
@@ -395,7 +369,6 @@ function MyForm() {
395
369
In the above example, a ref is created in the parent component, `MyForm`, and is passed to the child component, `MyInput`. `MyInput` then passes the ref to `<input>`. Because `<input>` is a [built-in component](/reference/react-dom/components/common) React sets the `.current` property of the ref to the `<input>` DOM element.
396
370
397
371
The `inputRef` created in `MyForm` now points to the `<input>` DOM element returned by `MyInput`. A click handler created in `MyForm` can access `inputRef` and call `focus()` to set the focus on `<input>`.
398
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
399
372
400
373
<Sandpack>
401
374
@@ -426,88 +399,18 @@ export default function MyForm() {
426
399
427
400
</Sandpack>
428
401
429
-
<<<<<<< HEAD
430
-
문제를 인지할 수 있도록, React는 콘솔에 오류 메시지를 출력합니다.
431
-
432
-
<ConsoleBlocklevel="error">
433
-
434
-
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?
435
-
436
-
</ConsoleBlock>
437
-
438
-
React는 기본적으로 다른 컴포넌트의 DOM 노드에 접근하는 것을 허용하지 않습니다. 컴포넌트의 자식도 예외는 아닙니다! 이것은 의도적인 설계입니다. Ref는 자제해서 사용해야 하는 탈출구입니다. 직접 다른 컴포넌트의 DOM 노드를 조작하는 것은 코드가 쉽게 깨지게 만듭니다.
439
-
440
-
대신 특정 컴포넌트에서 소유한 DOM 노드를 선택적으로 노출할 수 있습니다. 컴포넌트는 자식 중 하나에 ref를 "전달"하도록 지정할 수 있습니다. 여기 `MyInput`이 어떻게 `forwardRef` API를 사용할 수 있는지 살펴보세요.
441
-
442
-
```js
443
-
constMyInput=forwardRef((props, ref) => {
444
-
return<input {...props} ref={ref} />;
445
-
});
446
-
```
447
-
448
-
작동하는 원리는 다음과 같습니다.
449
-
450
-
1.`<MyInput ref={inputRef} />`으로 React가 대응되는 DOM 노드를 `inputRef.current`에 대입하도록 설정합니다. 하지만 이것은 전적으로 `MyInput` 컴포넌트의 선택에 달려 있습니다, 기본적으로는 이렇게 동작하지 않습니다.
451
-
2.`MyInput` 컴포넌트는 `forwardRef`를 통해 선언되었습니다. 이것은 `props` 다음에 선언된 **두 번째 `ref` 인수를 통해 상위의 `inputRef`를 받을 수 있도록 합니다.**
452
-
3.`MyInput`은 자체적으로 수신받은 `ref`를 컴포넌트 내부의 `<input>`으로 전달합니다.
453
-
454
-
이제 버튼을 클릭하면 input 요소로 포커스가 잘 이동합니다.
455
-
456
-
<Sandpack>
457
-
458
-
```js
459
-
import { forwardRef, useRef } from'react';
460
-
461
-
constMyInput=forwardRef((props, ref) => {
462
-
return<input {...props} ref={ref} />;
463
-
});
464
-
465
-
exportdefaultfunctionForm() {
466
-
constinputRef=useRef(null);
467
-
468
-
functionhandleClick() {
469
-
inputRef.current.focus();
470
-
}
471
-
472
-
return (
473
-
<>
474
-
<MyInput ref={inputRef} />
475
-
<button onClick={handleClick}>
476
-
Focus the input
477
-
</button>
478
-
</>
479
-
);
480
-
}
481
-
```
482
-
483
-
</Sandpack>
484
-
485
-
이 패턴은 디자인 시스템에서 버튼, 입력 요소 등의 저수준 컴포넌트에서 DOM 노드를 전달하기 위해 매우 흔하게 사용됩니다. 반면 폼, 목록 혹은 페이지 섹션 등의 고수준 컴포넌트에서는 의도하지 않은 DOM 구조 의존성 문제를 피하고자 일반적으로 DOM 노드를 노출하지 않습니다.
486
-
487
-
=======
488
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
489
402
<DeepDive>
490
403
491
404
#### 명령형 처리방식으로 하위 API 노출하기 {/*exposing-a-subset-of-the-api-with-an-imperative-handle*/}
492
405
493
-
<<<<<<< HEAD
494
406
위 예시에서 `MyInput` 컴포넌트는 DOM 입력 요소를 그대로 노출했습니다. 그리고 부모 컴포넌트에서 DOM 노드의 `focus()`를 호출할 수 있게 되었습니다. 하지만 이에 따라 부모 컴포넌트에서 DOM 노드의 CSS 스타일을 직접 변경하는 등의 예상치 못 한 작업을 할 수 있습니다. 몇몇 상황에서는 노출된 기능을 제한하고 싶을 수 있는데, 이 때 `useImperativeHandle`을 사용합니다.
495
-
=======
496
-
In the above example, the ref passed to `MyInput` is passed on to the original DOM input element. This lets the parent component call `focus()` on it. However, this also lets the parent component do something else--for example, change its CSS styles. In uncommon cases, you may want to restrict the exposed functionality. You can do that with [`useImperativeHandle`](/reference/react/useImperativeHandle):
497
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
407
+
408
+
In the above example, the ref passed to `MyInput` is passed on to the original DOM input element. This lets the parent component call `focus()` on it. However, this also lets the parent component do something else--for example, change its CSS styles. In uncommon cases, you may want to restrict the exposed functionality. You can do that with [`useImperativeHandle`](/reference/react/useImperativeHandle): {/*TODO*/}
@@ -538,11 +441,9 @@ export default function Form() {
538
441
539
442
</Sandpack>
540
443
541
-
<<<<<<< HEAD
542
-
여기 `MyInput` 내부의 `realInputRef`는 실제 input DOM 노드를 가지고 있습니다. 하지만 `useImperativeHandle`을 사용하여 React가 ref를 참조하는 부모 컴포넌트에 직접 구성한 객체를 전달하도록 지시합니다. 따라서 `Form` 컴포넌트 안쪽의 `inputRef.current`는 `foucs` 메서드만 가지고 있습니다. 이 경우 ref는 DOM 노드가 아니라 `useImperativeHandle` 호출에서 직접 구성한 객체가 됩니다.
543
-
=======
544
-
Here, `realInputRef` inside `MyInput` holds the actual input DOM node. However, [`useImperativeHandle`](/reference/react/useImperativeHandle) instructs React to provide your own special object as the value of a ref to the parent component. So `inputRef.current` inside the `Form` component will only have the `focus` method. In this case, the ref "handle" is not the DOM node, but the custom object you create inside [`useImperativeHandle`](/reference/react/useImperativeHandle) call.
545
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
444
+
여기 `MyInput` 내부의 `realInputRef`는 실제 input DOM 노드를 가지고 있습니다. 하지만 [`useImperativeHandle`](/reference/react/useImperativeHandle)을 사용하여 React가 ref를 참조하는 부모 컴포넌트에 직접 구성한 객체를 전달하도록 지시합니다. 따라서 `Form` 컴포넌트 안쪽의 `inputRef.current`는 `foucs` 메서드만 가지고 있습니다. 이 경우 ref는 DOM 노드가 아니라 [`useImperativeHandle`](/reference/react/useImperativeHandle) 호출에서 직접 구성한 객체가 됩니다.
445
+
446
+
Here, `realInputRef` inside `MyInput` holds the actual input DOM node. However, [`useImperativeHandle`](/reference/react/useImperativeHandle) instructs React to provide your own special object as the value of a ref to the parent component. So `inputRef.current` inside the `Form` component will only have the `focus` method. In this case, the ref "handle" is not the DOM node, but the custom object you create inside [`useImperativeHandle`](/reference/react/useImperativeHandle) call. {/*TODO*/}
React Developer Tools는 [React Native](https://reactnative.dev/)로 만들어진 앱에서도 잘 동작합니다.
58
-
59
-
React Developer Tools를 사용하는 가장 쉬운 방법은 전역적으로 설치하는 것입니다.
60
-
```bash
61
-
# Yarn
62
-
yarn global add react-devtools
63
-
=======
64
55
## Mobile (React Native) {/*mobile-react-native*/}
65
56
66
57
To inspect apps built with [React Native](https://reactnative.dev/), you can use [React Native DevTools](https://reactnative.dev/docs/react-native-devtools), the built-in debugger that deeply integrates React Developer Tools. All features work identically to the browser extension, including native element highlighting and selection.
67
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
68
58
69
59
[Learn more about debugging in React Native.](https://reactnative.dev/docs/debugging)
70
60
71
-
<<<<<<< HEAD
72
-
다음으로 터미널에서 개발자 도구를 여십시오.
73
-
```bash
74
-
react-devtools
75
-
```
76
-
77
-
실행 중인 로컬 React Native 앱에 연결해야 합니다.
78
-
79
-
> 개발자 도구가 몇 초 후에 연결되지 않으면 앱을 다시 로드해 보십시오.
80
-
81
-
[React Native 디버깅에 대하여 더 알아보기](https://reactnative.dev/docs/debugging)
82
-
=======
83
61
> For versions of React Native earlier than 0.76, please use the standalone build of React DevTools by following the [Safari and other browsers](#safari-and-other-browsers) guide above.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/link.md
+3-20Lines changed: 3 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,6 @@
2
2
link: "<link>"
3
3
---
4
4
5
-
<<<<<<< HEAD
6
-
<Canary>
7
-
8
-
React의 `<link>` 확장은 현재 React의 카나리(Canary) 채널과 실험 채널에서만 사용할 수 있습니다. React의 안정적인 릴리즈에서는 `<link>`가 [내장 브라우저 HTML 컴포넌트](https://react.dev/reference/react-dom/components#all-html-components)로만 작동합니다. 자세한 내용은 [React 릴리즈 채널](/community/versioning-policy#all-release-channels)에서 확인할 수 있습니다.
9
-
10
-
</Canary>
11
-
12
-
=======
13
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
14
5
<Intro>
15
6
16
7
[브라우저 내장 `<link>` 컴포넌트](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)는 스타일시트와 같은 외부 리소스를 사용하거나 링크 메타데이터로 문서를 주석 처리할 수 있게 해줍니다.
@@ -160,13 +151,9 @@ export default function SiteMapPage() {
스타일시트는 서로 충돌할 수 있으며, 이 경우 브라우저는 문서에서 나중에 오는 스타일시트를 적용합니다. React는 `precedence` 속성을 사용하여 스타일시트의 순서를 제어할 수 있도록 합니다. 이 예시에서는 두 개의 컴포넌트가 스타일시트를 렌더링하며, 더 높은 우선순위를 가진 스타일시트는 해당 컴포넌트를 더 먼저 렌더링하더라도 문서에서 나중에 배치됩니다.
154
+
스타일시트는 서로 충돌할 수 있으며, 이 경우 브라우저는 문서에서 나중에 오는 스타일시트를 적용합니다. React는 `precedence` 속성을 사용하여 스타일시트의 순서를 제어할 수 있도록 합니다. 이 예시에서는 세 개의 컴포넌트가 스타일시트를 렌더링하며, 더 높은 우선순위를 가진 스타일시트는 해당 컴포넌트를 더 먼저 렌더링하더라도 문서에서 나중에 배치됩니다.
165
155
166
-
{/*FIXME: this doesn't appear to actually work -- I guess precedence isn't implemented yet?*/}
167
-
=======
168
-
Stylesheets can conflict with each other, and when they do, the browser goes with the one that comes later in the document. React lets you control the order of stylesheets with the `precedence` prop. In this example, three components render stylesheets, and the ones with the same precedence are grouped together in the `<head>`.
169
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
156
+
Stylesheets can conflict with each other, and when they do, the browser goes with the one that comes later in the document. React lets you control the order of stylesheets with the `precedence` prop. In this example, three components render stylesheets, and the ones with the same precedence are grouped together in the `<head>`. {/*TODO*/}
Note the `precedence` values themselves are arbitrary and their naming is up to you. React will infer that precedence values it discovers first are "lower" and precedence values it discovers later are "higher".
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/meta.md
-10Lines changed: 0 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,6 @@
2
2
meta: "<meta>"
3
3
---
4
4
5
-
<<<<<<< HEAD
6
-
<Canary>
7
-
8
-
React의 `<meta>` 확장은 현재 React의 카나리(Canary) 버전 및 실험 채널에서만 사용할 수 있습니다. React의 안정적인 릴리즈에서는 `<meta>`가 [내장 브라우저 HTML 컴포넌트](/reference/react-dom/components#all-html-components)로만 작동합니다. 여기에서 [React의 릴리즈 채널](/community/versioning-policy#all-release-channels)에 대해 자세히 알아보십시오.
9
-
10
-
</Canary>
11
-
12
-
13
-
=======
14
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
15
5
<Intro>
16
6
17
7
[내장 브라우저 `<meta>` 컴포넌트](https://developer.mozilla.org/ko/docs/Web/HTML/Element/meta)를 사용하면 문서에 메타데이터를 추가할 수 있습니다.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/script.md
-9Lines changed: 0 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,6 @@
2
2
script: "<script>"
3
3
---
4
4
5
-
<<<<<<< HEAD
6
-
<Canary>
7
-
8
-
React의 `<script>` 확장은 현재 React의 카나리(Canary) 버전 및 실험 채널에서만 사용할 수 있습니다. React의 안정적인 릴리즈에서는 `<script>`가 [내장 브라우저 HTML 컴포넌트](https://react.dev/reference/react-dom/components#all-html-components)로만 작동합니다. 여기에서 [React의 릴리즈 채널](/community/versioning-policy#all-release-channels)에 대해 자세히 알아보십시오.
9
-
10
-
</Canary>
11
-
12
-
=======
13
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
14
5
<Intro>
15
6
16
7
[내장 브라우저 `<script>` 컴포넌트](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script)를 사용하면 문서에 스크립트를 추가할 수 있습니다.
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/style.md
+2-13Lines changed: 2 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,15 +2,6 @@
2
2
style: "<style>"
3
3
---
4
4
5
-
<<<<<<< HEAD
6
-
<Canary>
7
-
8
-
React의 `<title>` 확장은 현재 React의 카나리(Canary) 버전 및 실험 채널에서만 사용할 수 있습니다. React의 안정적인 릴리즈에서는 `<title>`이 [내장 브라우저 HTML 컴포넌트](/reference/react-dom/components#all-html-components)로만 작동합니다. 여기에서 [React 릴리즈 채널](/community/versioning-policy#all-release-channels)에 대해 자세히 알아보십시오.
9
-
10
-
</Canary>
11
-
12
-
=======
13
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
14
5
<Intro>
15
6
16
7
[내장된 브라우저 `<style>` 컴포넌트](https://developer.mozilla.org/ko/docs/Web/HTML/Element/style)를 사용하면 문서에 인라인 CSS 스타일시트를 추가할 수 있습니다.
@@ -72,15 +63,13 @@ React는 `<style>` 컴포넌트를 문서의 `<head>`로 이동시키고, 동일
72
63
73
64
컴포넌트가 올바르게 표시되기 위해 특정 CSS 스타일에 의존하는 경우, 컴포넌트 내에서 인라인 스타일시트를 렌더링할 수 있습니다.
74
65
75
-
<<<<<<< HEAD
76
66
`href`와 `precedence` 속성을 제공하면 스타일시트가 로딩되는 동안 컴포넌트가 일시 중지됩니다. (인라인 스타일시트의 경우에도 스타일시트가 참조하는 폰트와 이미지로 인해 로딩 시간이 발생할 수 있습니다.) `href` 속성은 스타일시트를 고유하게 식별해야 하며, 이를 통해 React는 동일한 href를 가진 스타일시트의 중복을 제거할 수 있습니다.
77
-
=======
67
+
78
68
The `href` prop should uniquely identify the stylesheet, because React will de-duplicate stylesheets that have the same `href`.
79
69
If you supply a `precedence` prop, React will reorder inline stylesheets based on the order these values appear in the component tree.
80
70
81
71
Inline stylesheets will not trigger Suspense boundaries while they're loading.
82
-
Even if they load async resources like fonts or images.
83
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
72
+
Even if they load async resources like fonts or images. {/*TODO*/}
Copy file name to clipboardExpand all lines: src/content/reference/react-dom/components/title.md
-10Lines changed: 0 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,16 +2,6 @@
2
2
title: "<title>"
3
3
---
4
4
5
-
<<<<<<< HEAD
6
-
<Canary>
7
-
8
-
React의 `<title>` 확장은 현재 React의 카나리(Canary) 버전 및 실험 채널에서만 사용할 수 있습니다. React의 안정적인 릴리즈에서는 `<title>`이 [내장 브라우저 HTML 컴포넌트](https://react.dev/reference/react-dom/components#all-html-components)로만 작동합니다. 여기에서 [React 릴리즈 채널](/community/versioning-policy#all-release-channels)에 대해 자세히 알아보십시오.
9
-
10
-
</Canary>
11
-
12
-
13
-
=======
14
-
>>>>>>> b1a249d597016c6584e4c186daa28b180cc9aafc
15
5
<Intro>
16
6
17
7
[내장된 브라우저 `<title>` 컴포넌트](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/title)를 사용하면 문서의 제목을 지정할 수 있습니다.
0 commit comments