Skip to content

Commit 474fe72

Browse files
authored
Merge pull request #689 from reactjs/tr/createRef
Translate "createRef"
2 parents 9b71176 + 83e4aa8 commit 474fe72

File tree

1 file changed

+23
-23
lines changed

1 file changed

+23
-23
lines changed

Diff for: src/content/reference/react/createRef.md

+23-23
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: createRef
44

55
<Pitfall>
66

7-
`createRef` is mostly used for [class components.](/reference/react/Component) Function components typically rely on [`useRef`](/reference/react/useRef) instead.
7+
`createRef` は主に[クラスコンポーネント](/reference/react/Component)で使用されます。関数コンポーネントでは通常代わりに [`useRef`](/reference/react/useRef) を用います。
88

99
</Pitfall>
1010

1111
<Intro>
1212

13-
`createRef` creates a [ref](/learn/referencing-values-with-refs) object which can contain arbitrary value.
13+
`createRef` は任意の値を保持できる [ref](/learn/referencing-values-with-refs) オブジェクトを作成します。
1414

1515
```js
1616
class MyInput extends Component {
@@ -25,11 +25,11 @@ class MyInput extends Component {
2525

2626
---
2727

28-
## Reference {/*reference*/}
28+
## リファレンス {/*reference*/}
2929

3030
### `createRef()` {/*createref*/}
3131

32-
Call `createRef` to declare a [ref](/learn/referencing-values-with-refs) inside a [class component.](/reference/react/Component)
32+
`createRef` を呼び出して、[クラスコンポーネント](/reference/react/Component)内で [ref](/learn/referencing-values-with-refs) を宣言します。
3333

3434
```js
3535
import { createRef, Component } from 'react';
@@ -40,31 +40,31 @@ class MyComponent extends Component {
4040
// ...
4141
```
4242
43-
[See more examples below.](#usage)
43+
[さらに例を見る](#usage)
4444
45-
#### Parameters {/*parameters*/}
45+
#### 引数 {/*parameters*/}
4646
47-
`createRef` takes no parameters.
47+
`createRef` は引数を取りません。
4848
49-
#### Returns {/*returns*/}
49+
#### 返り値 {/*returns*/}
5050
51-
`createRef` returns an object with a single property:
51+
`createRef` は単一のプロパティを持つオブジェクトを返します。
5252
53-
* `current`: Initially, it's set to the `null`. You can later set it to something else. If you pass the ref object to React as a `ref` attribute to a JSX node, React will set its `current` property.
53+
* `current`: `null` に初期化されています。後で他の値にセットすることができます。JSX ノードの `ref` 属性として React ref オブジェクトを渡すと、React はその `current` プロパティを適切にセットします。
5454
55-
#### Caveats {/*caveats*/}
55+
#### 注意点 {/*caveats*/}
5656
57-
* `createRef` always returns a *different* object. It's equivalent to writing `{ current: null }` yourself.
58-
* In a function component, you probably want [`useRef`](/reference/react/useRef) instead which always returns the same object.
59-
* `const ref = useRef()` is equivalent to `const [ref, _] = useState(() => createRef(null))`.
57+
* `createRef` は常に*異なる*オブジェクトを返します。これは自分で `{ current: null }` を書くのと同等です。
58+
* 関数コンポーネントでは、同じオブジェクトを常に返す [`useRef`](/reference/react/useRef) を代わりに使用することをお勧めします。
59+
* `const ref = useRef()` `const [ref, _] = useState(() => createRef(null))` と同等です。
6060
6161
---
6262
63-
## Usage {/*usage*/}
63+
## 使用法 {/*usage*/}
6464
65-
### Declaring a ref in a class component {/*declaring-a-ref-in-a-class-component*/}
65+
### クラスコンポーネントで ref を宣言する {/*declaring-a-ref-in-a-class-component*/}
6666
67-
To declare a ref inside a [class component,](/reference/react/Component) call `createRef` and assign its result to a class field:
67+
[クラスコンポーネント](/reference/react/Component)内で ref を宣言するには、`createRef` を呼び出し、その結果をクラスフィールドに割り当てます。
6868
6969
```js {4}
7070
import { Component, createRef } from 'react';
@@ -76,7 +76,7 @@ class Form extends Component {
7676
}
7777
```
7878
79-
If you now pass `ref={this.inputRef}` to an `<input>` in your JSX, React will populate `this.inputRef.current` with the input DOM node. For example, here is how you make a button that focuses the input:
79+
これで JSX の `<input>``ref={this.inputRef}` を渡すと、React `this.inputRef.current` input DOM ノードにセットします。例えば以下のようにして、input をフォーカスするボタンを作ることができます。
8080
8181
<Sandpack>
8282
@@ -107,17 +107,17 @@ export default class Form extends Component {
107107
108108
<Pitfall>
109109
110-
`createRef` is mostly used for [class components.](/reference/react/Component) Function components typically rely on [`useRef`](/reference/react/useRef) instead.
110+
`createRef` は主に[クラスコンポーネント](/reference/react/Component)で使用されます。関数コンポーネントでは通常代わりに [`useRef`](/reference/react/useRef) を用います。
111111
112112
</Pitfall>
113113
114114
---
115115
116-
## Alternatives {/*alternatives*/}
116+
## 代替手段 {/*alternatives*/}
117117
118-
### Migrating from a class with `createRef` to a function with `useRef` {/*migrating-from-a-class-with-createref-to-a-function-with-useref*/}
118+
### `createRef` を使ったクラスから `useRef` を使った関数への移行 {/*migrating-from-a-class-with-createref-to-a-function-with-useref*/}
119119
120-
We recommend using function components instead of [class components](/reference/react/Component) in new code. If you have some existing class components using `createRef`, here is how you can convert them. This is the original code:
120+
新しいコードでは[クラスコンポーネント](/reference/react/Component)の代わりに関数コンポーネントの使用を推奨します。以下に、`createRef` を使用している既存のクラスコンポーネントがある場合の移行方法を示します。こちらが元のコードです。
121121
122122
<Sandpack>
123123
@@ -146,7 +146,7 @@ export default class Form extends Component {
146146
147147
</Sandpack>
148148
149-
When you [convert this component from a class to a function,](/reference/react/Component#alternatives) replace calls to `createRef` with calls to [`useRef`:](/reference/react/useRef)
149+
このコンポーネントを[クラスから関数に移行する](/reference/react/Component#alternatives)場合、`createRef` の呼び出しを [`useRef`](/reference/react/useRef) の呼び出しに置き換えます。
150150
151151
<Sandpack>
152152

0 commit comments

Comments
 (0)