Skip to content

Commit 9f1503a

Browse files
committed
Translate "findDOMNode"
1 parent aff743b commit 9f1503a

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

src/content/reference/react-dom/findDOMNode.md

+37-37
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: findDOMNode
44

55
<Deprecated>
66

7-
This API will be removed in a future major version of React. [See the alternatives.](#alternatives)
7+
この API は、将来の React のメジャーバージョンで削除される予定です。[こちらの代替案を参照してください。](#alternatives)
88

99
</Deprecated>
1010

1111
<Intro>
1212

13-
`findDOMNode` finds the browser DOM node for a React [class component](/reference/react/Component) instance.
13+
`findDOMNode` は、React [class component](/reference/react/Component) インスタンスのブラウザ DOM ノードを見つけます。
1414

1515
```js
1616
const domNode = findDOMNode(componentInstance)
@@ -22,46 +22,46 @@ const domNode = findDOMNode(componentInstance)
2222

2323
---
2424

25-
## Reference {/*reference*/}
25+
## リファレンス {/*reference*/}
2626

2727
### `findDOMNode(componentInstance)` {/*finddomnode*/}
2828

29-
Call `findDOMNode` to find the browser DOM node for a given React [class component](/reference/react/Component) instance.
29+
`findDOMNode` を呼び出して、指定された React [class component](/reference/react/Component) インスタンスのブラウザ DOM ノードを見つけます。
3030

3131
```js
3232
import { findDOMNode } from 'react-dom';
3333

3434
const domNode = findDOMNode(componentInstance);
3535
```
3636

37-
[See more examples below.](#usage)
37+
[さらに例を見る](#usage)
3838

39-
#### Parameters {/*parameters*/}
39+
#### 引数 {/*parameters*/}
4040

41-
* `componentInstance`: An instance of the [`Component`](/reference/react/Component) subclass. For example, `this` inside a class component.
41+
* `componentInstance`: [Component](/reference/react/Component) サブクラスのインスタンス。例えば、クラスコンポーネントにある this
4242

4343

44-
#### Returns {/*returns*/}
44+
#### 戻り値 {/*returns*/}
4545

46-
`findDOMNode` returns the first closest browser DOM node within the given `componentInstance`. When a component renders to `null`, or renders `false`, `findDOMNode` returns `null`. When a component renders to a string, `findDOMNode` returns a text DOM node containing that value.
46+
`findDOMNode` は、指定された `componentInstance` にある最も近いブラウザ DOM ノードを返します。コンポーネントが `null` をレンダーする場合や `false` をレンダーする場合、`findDOMNode` `null` を返します。コンポーネントが文字列をレンダーする場合は `findDOMNode` は値を含むテキスト DOM ノードを返します。
4747

48-
#### Caveats {/*caveats*/}
48+
#### 注意点 {/*caveats*/}
4949

50-
* A component may return an array or a [Fragment](/reference/react/Fragment) with multiple children. In that case `findDOMNode`, will return the DOM node corresponding to the first non-empty child.
50+
* コンポーネントは、配列や複数の子要素を持つ [Fragment](/reference/react/Fragment) を返すことができます。その場合、`findDOMNode` は、最初の空でない子に対応する DOM ノードを返します。
5151

52-
* `findDOMNode` only works on mounted components (that is, components that have been placed in the DOM). If you try to call this on a component that has not been mounted yet (like calling `findDOMNode()` in `render()` on a component that has yet to be created), an exception will be thrown.
52+
* `findDOMNode` はマウントされたコンポーネント(つまり、DOM に配置されたコンポーネント)でのみ動作します。まだ作成されていないコンポーネントの `render()` 内で `findDOMNode()` を呼び出そうとすると、例外がスローされます。
5353

54-
* `findDOMNode` only returns the result at the time of your call. If a child component renders a different node later, there is no way for you to be notified of this change.
54+
* `findDOMNode` は、呼び出したときの結果のみを返します。子コンポーネントが後で異なるノードをレンダーする場合、この変更を通知されません。
5555

56-
* `findDOMNode` accepts a class component instance, so it can't be used with function components.
56+
* `findDOMNode` はクラスコンポーネントインスタンスを受け取るため、関数コンポーネントで使用することはできません。
5757

5858
---
5959

60-
## Usage {/*usage*/}
60+
## 使用法 {/*usage*/}
6161

62-
### Finding the root DOM node of a class component {/*finding-the-root-dom-node-of-a-class-component*/}
62+
### クラスコンポーネントのルート DOM ノードを見つける {/*finding-the-root-dom-node-of-a-class-component*/}
6363

64-
Call `findDOMNode` with a [class component](/reference/react/Component) instance (usually, `this`) to find the DOM node it has rendered.
64+
[class component](reference/react/Component) インスタンス(通常は、`this`)を使用して `findDOMNode` を呼び出し、レンダーされた DOM ノードを見つけます。
6565

6666
```js {3}
6767
class AutoselectingInput extends Component {
@@ -76,7 +76,7 @@ class AutoselectingInput extends Component {
7676
}
7777
```
7878

79-
Here, the `input` variable will be set to the `<input>` DOM element. This lets you do something with it. For example, when clicking "Show example" below mounts the input, [`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) selects all text in the input:
79+
ここで、`input` 変数は `<input>` DOM 要素にセットされます。これにより、それを使用して何かを行うことができます。例えば、以下の "Show example" をクリックすると input はマウントされ、[`input.select()`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/select) input にあるすべてのテキストを選択します。
8080

8181
<Sandpack>
8282

@@ -120,11 +120,11 @@ export default AutoselectingInput;
120120

121121
---
122122

123-
## Alternatives {/*alternatives*/}
123+
## 代替手段 {/*alternatives*/}
124124

125-
### Reading component's own DOM node from a ref {/*reading-components-own-dom-node-from-a-ref*/}
125+
### ref からコンポーネントの独自の DOM ノードを読み取る {/*reading-components-own-dom-node-from-a-ref*/}
126126

127-
Code using `findDOMNode` is fragile because the connection between the JSX node and the code manipulating the corresponding DOM node is not explicit. For example, try wrapping this `<input />` into a `<div>`:
127+
`findDOMNode` を使用するコードは壊れやすいです。なぜなら JSX ノードと対応する DOM ノードを操作するコードとの間の接続が明示的でないためです。例えば、この `<input />` `<div>` でラップしてみてください。
128128

129129
<Sandpack>
130130

@@ -165,9 +165,9 @@ export default AutoselectingInput;
165165

166166
</Sandpack>
167167

168-
This will break the code because now, `findDOMNode(this)` finds the `<div>` DOM node, but the code expects an `<input>` DOM node. To avoid these kinds of problems, use [`createRef`](/reference/react/createRef) to manage a specific DOM node.
168+
このコードは壊れます。なぜなら、`findDOMNode(this)` `<div>` DOM ノードを見つけるようになったからですが、コードは `<input>` DOM ノードを期待しています。このような問題を避けるために、特定の DOM ノードを管理するために [`createRef`](/reference/react/createRef) を使用してください。
169169

170-
In this example, `findDOMNode` is no longer used. Instead, `inputRef = createRef(null)` is defined as an instance field on the class. To read the DOM node from it, you can use `this.inputRef.current`. To attach it to the JSX, you render `<input ref={this.inputRef} />`. This connects the code using the DOM node to its JSX:
170+
この例では、`findDOMNode` は使用されていません。代わりに、`inputRef = createRef(null)` がクラスのインスタンスフィールドとして定義されています。DOM ノードを読み取るには、`this.inputRef.current` を使用できます。それを JSX にアタッチするには、`<input ref={this.inputRef} />` をレンダーします。これにより、DOM ノードを使用するコードがその JSX に接続されます。
171171

172172
<Sandpack>
173173

@@ -212,7 +212,7 @@ export default AutoselectingInput;
212212

213213
</Sandpack>
214214

215-
In modern React without class components, the equivalent code would call [`useRef`](/reference/react/useRef) instead:
215+
クラスコンポーネントがないモダンな React では、代わりに [`useRef`](/reference/react/useRef) を呼び出すコードになります。
216216

217217
<Sandpack>
218218

@@ -251,13 +251,13 @@ export default function AutoselectingInput() {
251251

252252
</Sandpack>
253253

254-
[Read more about manipulating the DOM with refs.](/learn/manipulating-the-dom-with-refs)
254+
[refs を使用して DOM を操作する方法についての詳細はこちら](/learn/manipulating-the-dom-with-refs)
255255

256256
---
257257

258-
### Reading a child component's DOM node from a forwarded ref {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
258+
### forwarded ref から子コンポーネントの DOM ノードを読み取る {/*reading-a-child-components-dom-node-from-a-forwarded-ref*/}
259259

260-
In this example, `findDOMNode(this)` finds a DOM node that belongs to another component. The `AutoselectingInput` renders `MyInput`, which is your own component that renders a browser `<input>`.
260+
この例では、`findDOMNode(this)` は別のコンポーネントに属する DOM ノードを見つけます。`AutoselectingInput` は、ブラウザの `<input>` をレンダーする独自のコンポーネントである `MyInput` をレンダーします。
261261

262262
<Sandpack>
263263

@@ -305,14 +305,14 @@ export default function MyInput() {
305305

306306
</Sandpack>
307307

308-
Notice that calling `findDOMNode(this)` inside `AutoselectingInput` still gives you the DOM `<input>`--even though the JSX for this `<input>` is hidden inside the `MyInput` component. This seems convenient for the above example, but it leads to fragile code. Imagine that you wanted to edit `MyInput` later and add a wrapper `<div>` around it. This would break the code of `AutoselectingInput` (which expects to find an `<input>`).
308+
`AutoselectingInput` 内にある `findDOMNode(this)` を呼び出すと、DOM `<input>` を取得します。しかし、この `<input>` の JSX は `MyInput` コンポーネントの中に隠れています。この上の例では便利に思えますが、壊れやすいコードになりやすいです。後で MyInput を編集して、それをラップする `<div>` を追加するとどうなるでしょうか。`AutoselectingInput` のコードが壊れます(`<input>` が見つかることを期待している)。
309309

310-
To replace `findDOMNode` in this example, the two components need to coordinate:
310+
この例の `findDOMNode` を置き換えるには、2 つのコンポーネントが連携する必要があります:
311311

312-
1. `AutoSelectingInput` should declare a ref, like [in the earlier example](#reading-components-own-dom-node-from-a-ref), and pass it to `<MyInput>`.
313-
2. `MyInput` should be declared with [`forwardRef`](/reference/react/forwardRef) to take that ref and forward it down to the `<input>` node.
312+
- 1.`AutoSelectingInput` `ref` を宣言し、[前述の例](#reading-components-own-dom-node-from-a-ref)のように `<MyInput>` に渡す必要があります。
313+
- 2.`MyInput` `forwardRef` で宣言され、その `ref` を取り、それを `<input>` ノードに転送する必要があります。
314314

315-
This version does that, so it no longer needs `findDOMNode`:
315+
このバージョンはそれを行うので、もはや `findDOMNode` は必要ありません。
316316

317317
<Sandpack>
318318

@@ -368,7 +368,7 @@ export default MyInput;
368368

369369
</Sandpack>
370370

371-
Here is how this code would look like with function components instead of classes:
371+
以下は、クラスコンポーネントの代わりに関数コンポーネントを使用した場合のコードの見た目です:
372372

373373
<Sandpack>
374374

@@ -420,16 +420,16 @@ export default MyInput;
420420

421421
---
422422

423-
### Adding a wrapper `<div>` element {/*adding-a-wrapper-div-element*/}
423+
### `<div>` 要素のラッパーを追加する {/*adding-a-wrapper-div-element*/}
424424

425-
Sometimes a component needs to know the position and size of its children. This makes it tempting to find the children with `findDOMNode(this)`, and then use DOM methods like [`getBoundingClientRect`](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) for measurements.
425+
コンポーネントは時々、子要素の位置やサイズを知る必要があります。`findDOMNode(this)` で子要素を見つけ、`getBoundingClientRect` のような測定するために DOM メソッドを使用できるのは魅力になります。
426426

427-
There is currently no direct equivalent for this use case, which is why `findDOMNode` is deprecated but is not yet removed completely from React. In the meantime, you can try rendering a wrapper `<div>` node around the content as a workaround, and getting a ref to that node. However, extra wrappers can break styling.
427+
現在、このユースケースに直接対応できるものは存在しないため、`findDOMNode` が非推奨となっていますが、まだ完全に React から削除されていません。その間、コンテンツの周りにラッパーとして `<div>` ノードをレンダーし、そのノードへの ref を取得するという回避策を試すことができます。ただし、余分なラッパーはスタイリングを壊す可能性があります。
428428

429429
```js
430430
<div ref={someRef}>
431431
{children}
432432
</div>
433433
```
434434

435-
This also applies to focusing and scrolling to arbitrary children.
435+
これは、任意の子要素にフォーカスしたり、スクロールしたりする場合にも適用されます。

0 commit comments

Comments
 (0)