Skip to content

Commit 9b71176

Browse files
authored
Merge pull request #688 from reactjs/tr/createElement
Translate "createElement"
2 parents dd55f92 + 29aa7bf commit 9b71176

File tree

1 file changed

+34
-34
lines changed

1 file changed

+34
-34
lines changed

src/content/reference/react/createElement.md

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

55
<Intro>
66

7-
`createElement` lets you create a React element. It serves as an alternative to writing [JSX.](/learn/writing-markup-with-jsx)
7+
`createElement` によって React 要素を作成できます。これは [JSX](/learn/writing-markup-with-jsx) を書く代わりの手段として利用できます。
88

99
```js
1010
const element = createElement(type, props, ...children)
@@ -16,11 +16,11 @@ const element = createElement(type, props, ...children)
1616

1717
---
1818

19-
## Reference {/*reference*/}
19+
## リファレンス {/*reference*/}
2020

2121
### `createElement(type, props, ...children)` {/*createelement*/}
2222

23-
Call `createElement` to create a React element with the given `type`, `props`, and `children`.
23+
`createElement` を呼び出して、指定した `type``props``children` を持った React 要素を作成します。
2424

2525
```js
2626
import { createElement } from 'react';
@@ -34,44 +34,44 @@ function Greeting({ name }) {
3434
}
3535
```
3636

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

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

41-
* `type`: The `type` argument must be a valid React component type. For example, it could be a tag name string (such as `'div'` or `'span'`), or a React component (a function, a class, or a special component like [`Fragment`](/reference/react/Fragment)).
41+
* `type`: `type` 引数は有効な React のコンポーネント型でなければなりません。例えば、タグ名の文字列(`'div'` `'span'`)や、React コンポーネント(関数、クラス、または [`Fragment`](/reference/react/Fragment) のような特別なコンポーネント)が該当します。
4242

43-
* `props`: The `props` argument must either be an object or `null`. If you pass `null`, it will be treated the same as an empty object. React will create an element with props matching the `props` you have passed. Note that `ref` and `key` from your `props` object are special and will *not* be available as `element.props.ref` and `element.props.key` on the returned `element`. They will be available as `element.ref` and `element.key`.
43+
* `props`: `props` 引数はオブジェクトか `null` でなければなりません。`null` を渡すと、空のオブジェクトと同じように扱われます。React は、渡された `props` と同じ props を持った要素を作成します。`props` オブジェクトの `ref` `key` は特別であり、返された `element``element.props.ref` `element.props.key` として*利用できません*`element.ref` ないし `element.key` となります。
4444

45-
* **optional** `...children`: Zero or more child nodes. They can be any React nodes, including React elements, strings, numbers, [portals](/reference/react-dom/createPortal), empty nodes (`null`, `undefined`, `true`, and `false`), and arrays of React nodes.
45+
* **省略可能** `...children`: ゼロ個以上の子ノード。これらは React ノード、つまり、React 要素、文字列、数値、[ポータル](/reference/react-dom/createPortal)、空ノード(`null``undefined``true``false`)、あるいは React ノードの配列となります。
4646

47-
#### Returns {/*returns*/}
47+
#### 返り値 {/*returns*/}
4848

49-
`createElement` returns a React element object with a few properties:
49+
`createElement` は以下のプロパティを持つ React 要素オブジェクトを返します。
5050

51-
* `type`: The `type` you have passed.
52-
* `props`: The `props` you have passed except for `ref` and `key`. If the `type` is a component with legacy `type.defaultProps`, then any missing or undefined `props` will get the values from `type.defaultProps`.
53-
* `ref`: The `ref` you have passed. If missing, `null`.
54-
* `key`: The `key` you have passed, coerced to a string. If missing, `null`.
51+
* `type`: 指定した `type`
52+
* `props`: 指定した `props`、ただし `ref` `key` は除く。もし `type` がレガシーの `type.defaultProps` を持つコンポーネントであれば、欠けているか undefined となっている `props` `type.defaultProps` から値を取得します。
53+
* `ref`: 指定した `ref`。未指定の場合は `null`
54+
* `key`: 指定した `key`。強制的に文字列に変換されます。未指定の場合は `null`
5555

56-
Usually, you'll return the element from your component or make it a child of another element. Although you may read the element's properties, it's best to treat every element as opaque after it's created, and only render it.
56+
通常、この要素をコンポーネントから返すか、他の要素の子として用います。要素のプロパティを読み取ることは可能ですが、作成後は要素の構造を非公開 (opaque) として扱い、レンダーのみ行うようにするべきです。
5757

58-
#### Caveats {/*caveats*/}
58+
#### 注意点 {/*caveats*/}
5959

60-
* You must **treat React elements and their props as [immutable](https://en.wikipedia.org/wiki/Immutable_object)** and never change their contents after creation. In development, React will [freeze](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) the returned element and its `props` property shallowly to enforce this.
60+
* **React 要素とその props [イミュータブル (immutable)](https://en.wikipedia.org/wiki/Immutable_object) として扱い**、作成後にその内容を変更してはなりません。これを強制するために、React は開発環境において、返された要素とその `props` プロパティを浅く[凍結 (freeze)](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) します。
6161

62-
* When you use JSX, **you must start a tag with a capital letter to render your own custom component.** In other words, `<Something />` is equivalent to `createElement(Something)`, but `<something />` (lowercase) is equivalent to `createElement('something')` (note it's a string, so it will be treated as a built-in HTML tag).
62+
* JSX を使用する場合、**独自のカスタムコンポーネントをレンダーするためにはタグを大文字で始める必要があります**。つまり、`<Something />` `createElement(Something)` と同等ですが、`<something />`(小文字)は `createElement('something')` と同等です(文字列なので、組み込みの HTML タグとして扱われます)。
6363

64-
* You should only **pass children as multiple arguments to `createElement` if they are all statically known,** like `createElement('h1', {}, child1, child2, child3)`. If your children are dynamic, pass the entire array as the third argument: `createElement('ul', {}, listItems)`. This ensures that React will [warn you about missing `key`s](/learn/rendering-lists#keeping-list-items-in-order-with-key) for any dynamic lists. For static lists this is not necessary because they never reorder.
64+
* **複数の子の内容がすべて静的に分かっている場合**`createElement` には子を `createElement('h1', {}, child1, child2, child3)` のように**複数の引数として渡してください**。子が動的な場合は、配列全体を第 3 引数として `createElement('ul', {}, listItems)` のように渡してください。これにより、React は動的なリストに `key` が欠けている場合に[警告を出す](/learn/rendering-lists#keeping-list-items-in-order-with-key)ようになります。静的なリストでは並び替えは決して発生しないため、key は必要ありません。
6565

6666
---
6767

68-
## Usage {/*usage*/}
68+
## 使用法 {/*usage*/}
6969

70-
### Creating an element without JSX {/*creating-an-element-without-jsx*/}
70+
### JSX を使わずに要素を作成する {/*creating-an-element-without-jsx*/}
7171

72-
If you don't like [JSX](/learn/writing-markup-with-jsx) or can't use it in your project, you can use `createElement` as an alternative.
72+
[JSX](/learn/writing-markup-with-jsx) が好きでない場合や、プロジェクトで使用できない場合には、代わりに `createElement` を使用できます。
7373

74-
To create an element without JSX, call `createElement` with some <CodeStep step={1}>type</CodeStep>, <CodeStep step={2}>props</CodeStep>, and <CodeStep step={3}>children</CodeStep>:
74+
JSX を使わずに要素を作成するには、`createElement` を呼び出して、何らかの <CodeStep step={1}>type</CodeStep><CodeStep step={2}>props</CodeStep><CodeStep step={3}>children</CodeStep> を引数として渡します。
7575

7676
```js [[1, 5, "'h1'"], [2, 6, "{ className: 'greeting' }"], [3, 7, "'Hello ',"], [3, 8, "createElement('i', null, name),"], [3, 9, "'. Welcome!'"]]
7777
import { createElement } from 'react';
@@ -87,7 +87,7 @@ function Greeting({ name }) {
8787
}
8888
```
8989

90-
The <CodeStep step={3}>children</CodeStep> are optional, and you can pass as many as you need (the example above has three children). This code will display a `<h1>` header with a greeting. For comparison, here is the same example rewritten with JSX:
90+
<CodeStep step={3}>children</CodeStep> はオプションで、必要なだけ渡すことができます(上記の例では子が 3 つあります)。このコードは、`<h1>` ヘッダに挨拶文字列を入れて表示します。比較のため、以下に JSX を使って書き直した同じ例を示します。
9191

9292
```js [[1, 3, "h1"], [2, 3, "className=\\"greeting\\""], [3, 4, "Hello <i>{name}</i>. Welcome!"], [1, 5, "h1"]]
9393
function Greeting({ name }) {
@@ -99,23 +99,23 @@ function Greeting({ name }) {
9999
}
100100
```
101101

102-
To render your own React component, pass a function like `Greeting` as the <CodeStep step={1}>type</CodeStep> instead of a string like `'h1'`:
102+
自身のカスタム React コンポーネントをレンダーするには、`'h1'` のような文字列ではなく `Greeting` のような関数を <CodeStep step={1}>type</CodeStep> として渡します。
103103

104104
```js [[1, 2, "Greeting"], [2, 2, "{ name: 'Taylor' }"]]
105105
export default function App() {
106106
return createElement(Greeting, { name: 'Taylor' });
107107
}
108108
```
109109

110-
With JSX, it would look like this:
110+
JSX を使用した場合は以下のようになります。
111111

112112
```js [[1, 2, "Greeting"], [2, 2, "name=\\"Taylor\\""]]
113113
export default function App() {
114114
return <Greeting name="Taylor" />;
115115
}
116116
```
117117

118-
Here is a complete example written with `createElement`:
118+
以下は、`createElement` を使用して書かれたフルのサンプルです。
119119

120120
<Sandpack>
121121

@@ -149,7 +149,7 @@ export default function App() {
149149

150150
</Sandpack>
151151

152-
And here is the same example written using JSX:
152+
同じものを JSX で書くと以下のようになります。
153153

154154
<Sandpack>
155155

@@ -176,13 +176,13 @@ export default function App() {
176176

177177
</Sandpack>
178178

179-
Both coding styles are fine, so you can use whichever one you prefer for your project. The main benefit of using JSX compared to `createElement` is that it's easy to see which closing tag corresponds to which opening tag.
179+
どちらのコーディングスタイルも問題ありませんので、プロジェクトに合わせて好きな方を使用してください。`createElement` と比較して JSX を使用する場合の主な利点は、どの閉じタグがどの開きタグに対応しているかが簡単にわかることです。
180180

181181
<DeepDive>
182182

183-
#### What is a React element, exactly? {/*what-is-a-react-element-exactly*/}
183+
#### React 要素とは要するに何なのか? {/*what-is-a-react-element-exactly*/}
184184

185-
An element is a lightweight description of a piece of the user interface. For example, both `<Greeting name="Taylor" />` and `createElement(Greeting, { name: 'Taylor' })` produce an object like this:
185+
要素 (element) とは、ユーザインターフェースの軽量な説明書きのことです。例えば、`<Greeting name="Taylor" />` `createElement(Greeting, { name: 'Taylor' })` はいずれも、次のようなオブジェクトを生成します。
186186

187187
```js
188188
// Slightly simplified
@@ -196,10 +196,10 @@ An element is a lightweight description of a piece of the user interface. For ex
196196
}
197197
```
198198

199-
**Note that creating this object does not render the `Greeting` component or create any DOM elements.**
199+
**このオブジェクトを作成しただけでは、`Greeting` コンポーネントがレンダーされたり、DOM 要素が作成されたりするわけではないことに注意してください**
200200

201-
A React element is more like a description--an instruction for React to later render the `Greeting` component. By returning this object from your `App` component, you tell React what to do next.
201+
React 要素とは、むしろ指示書のようなものです。React に後で `Greeting` コンポーネントをレンダーするよう指示するものです。このオブジェクトを `App` コンポーネントから返すことで、React に次に何をすべきかを伝えるのです。
202202

203-
Creating elements is extremely cheap so you don't need to try to optimize or avoid it.
203+
要素の作成は非常に安価であるため、最適化したり避けたりする必要はありません。
204204

205205
</DeepDive>

0 commit comments

Comments
 (0)