Skip to content

Commit 086248b

Browse files
authored
Merge pull request #567 from reactjs/tr/interactivity
Translate first 3 articles under "Adding Interactivity"
2 parents 2c67bf7 + a94155d commit 086248b

File tree

5 files changed

+250
-250
lines changed

5 files changed

+250
-250
lines changed

Diff for: src/content/learn/adding-interactivity.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ button { margin-right: 10px; }
6868

6969
<LearnMore path="/learn/responding-to-events">
7070

71-
イベントハンドラの追加方法を学ぶには **[イベント対応](/learn/responding-to-events)** を読んでみましょう。
71+
イベントハンドラの追加方法を学ぶには **[イベントへの応答](/learn/responding-to-events)** を読んでみましょう。
7272

7373
</LearnMore>
7474

Diff for: src/content/learn/render-and-commit.md

+54-54
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
11
---
2-
title: Render and Commit
2+
title: レンダーとコミット
33
---
44

55
<Intro>
66

7-
Before your components are displayed on screen, they must be rendered by React. Understanding the steps in this process will help you think about how your code executes and explain its behavior.
7+
コンポーネントは画面上に表示される前に、React によってレンダーされる必要があります。このプロセスを段階ごとに理解すると、コードがどのように実行されるのか考える際や、コードの振る舞いを説明する際に役立ちます。
88

99
</Intro>
1010

1111
<YouWillLearn>
1212

13-
* What rendering means in React
14-
* When and why React renders a component
15-
* The steps involved in displaying a component on screen
16-
* Why rendering does not always produce a DOM update
13+
* React での「レンダー」の意味
14+
* いつ、なぜ React はコンポーネントをレンダーするのか
15+
* 画面上にコンポーネントが表示されるステップ
16+
* なぜレンダーしても必ずしも DOM 更新が起きないのか
1717

1818
</YouWillLearn>
1919

20-
Imagine that your components are cooks in the kitchen, assembling tasty dishes from ingredients. In this scenario, React is the waiter who puts in requests from customers and brings them their orders. This process of requesting and serving UI has three steps:
20+
コンポーネントは厨房で材料から美味しい料理を作る料理人だと想像してください。このシナリオでは React はお客様のリクエストを受け付け、注文された料理を運ぶウェイターです。注文を受けて UI 要素を「配膳」するプロセスには、次の 3 つのステップが存在します:
2121

22-
1. **Triggering** a render (delivering the guest's order to the kitchen)
23-
2. **Rendering** the component (preparing the order in the kitchen)
24-
3. **Committing** to the DOM (placing the order on the table)
22+
1. レンダーの**トリガ**(キッチンに注文を送る)
23+
2. コンポーネントの**レンダー**(キッチンで注文を準備する)
24+
3. DOM への**コミット**(テーブルに注文を置く)
2525

2626
<IllustrationBlock sequential>
27-
<Illustration caption="Trigger" alt="React as a server in a restaurant, fetching orders from the users and delivering them to the Component Kitchen." src="/images/docs/illustrations/i_render-and-commit1.png" />
28-
<Illustration caption="Render" alt="The Card Chef gives React a fresh Card component." src="/images/docs/illustrations/i_render-and-commit2.png" />
29-
<Illustration caption="Commit" alt="React delivers the Card to the user at their table." src="/images/docs/illustrations/i_render-and-commit3.png" />
27+
<Illustration caption="トリガ" alt="レストランのウェイターとしての React が、ユーザからの注文を取って、Component Kitchen に運んでいる。" src="/images/docs/illustrations/i_render-and-commit1.png" />
28+
<Illustration caption="レンダー" alt="Card Chef React に新鮮な Card コンポーネントを渡している。" src="/images/docs/illustrations/i_render-and-commit2.png" />
29+
<Illustration caption="コミット" alt="React がテーブルのユーザに Card を配っている。" src="/images/docs/illustrations/i_render-and-commit3.png" />
3030
</IllustrationBlock>
3131

32-
## Step 1: Trigger a render {/*step-1-trigger-a-render*/}
32+
## ステップ 1:レンダーのトリガ {/*step-1-trigger-a-render*/}
3333

34-
There are two reasons for a component to render:
34+
コンポーネントがレンダーされる理由には 2 つあります。
3535

36-
1. It's the component's **initial render.**
37-
2. The component's (or one of its ancestors') **state has been updated.**
36+
1. コンポーネントの**初回レンダー**
37+
2. コンポーネント(またはその祖先のいずれか)の **state の更新**
3838

39-
### Initial render {/*initial-render*/}
39+
### 初回レンダー {/*initial-render*/}
4040

41-
When your app starts, you need to trigger the initial render. Frameworks and sandboxes sometimes hide this code, but it's done by calling [`createRoot`](/reference/react-dom/client/createRoot) with the target DOM node, and then calling its `render` method with your component:
41+
アプリが開始するときには、初回のレンダーをトリガする必要があります。フレームワークやサンドボックスでは、このコードが隠されたりすることがありますが、これはターゲットとなる DOM ノードで [`createRoot`](/reference/react-dom/client/createRoot) を呼び出し、コンポーネントでその `render` メソッドを呼び出すことによって行われます。
4242

4343
<Sandpack>
4444

@@ -63,28 +63,28 @@ export default function Image() {
6363

6464
</Sandpack>
6565

66-
Try commenting out the `root.render()` call and see the component disappear!
66+
`root.render()` の呼び出しをコメントアウトして、コンポーネントが消えるのを確認してみてください!
6767

68-
### Re-renders when state updates {/*re-renders-when-state-updates*/}
68+
### state 更新後の再レンダー {/*re-renders-when-state-updates*/}
6969

70-
Once the component has been initially rendered, you can trigger further renders by updating its state with the [`set` function.](/reference/react/useState#setstate) Updating your component's state automatically queues a render. (You can imagine these as a restaurant guest ordering tea, dessert, and all sorts of things after putting in their first order, depending on the state of their thirst or hunger.)
70+
コンポーネントが最初にレンダーされた後、[`set` 関数](/reference/react/useState#setstate)を使って state を更新することで、さらなるレンダーをトリガすることができます。コンポーネントの state を更新すると、自動的にレンダーがキューイングされます。(これは、レストランの客が最初の注文の後に、喉の渇きや空腹の状態に応じてお茶やデザートなどいろいろなものを注文するようなものだと考えることができます。)
7171

7272
<IllustrationBlock sequential>
73-
<Illustration caption="State update..." alt="React as a server in a restaurant, serving a Card UI to the user, represented as a patron with a cursor for their head. They patron expresses they want a pink card, not a black one!" src="/images/docs/illustrations/i_rerender1.png" />
74-
<Illustration caption="...triggers..." alt="React returns to the Component Kitchen and tells the Card Chef they need a pink Card." src="/images/docs/illustrations/i_rerender2.png" />
75-
<Illustration caption="...render!" alt="The Card Chef gives React the pink Card." src="/images/docs/illustrations/i_rerender3.png" />
73+
<Illustration caption="state の更新..." alt="レストランのウェイターとしての React Card UI を提供したところ。矢印頭の顧客は、黒ではなく、ピンクのカードが欲しいのだと注文している。" src="/images/docs/illustrations/i_rerender1.png" />
74+
<Illustration caption="... トリガ ..." alt="React Component Kitchenに戻り、ピンクの Card が必要だとシェフに伝える。" src="/images/docs/illustrations/i_rerender2.png" />
75+
<Illustration caption="... レンダー!" alt="Card シェフはピンクのカードを React に渡している。" src="/images/docs/illustrations/i_rerender3.png" />
7676
</IllustrationBlock>
7777

78-
## Step 2: React renders your components {/*step-2-react-renders-your-components*/}
78+
## ステップ 2:React がコンポーネントをレンダー {/*step-2-react-renders-your-components*/}
7979

80-
After you trigger a render, React calls your components to figure out what to display on screen. **"Rendering" is React calling your components.**
80+
あなたがレンダーをトリガした後、React はコンポーネントを呼び出して画面に表示する内容を把握します。**「レンダー」とは、React がコンポーネントを呼び出すことです。**
8181

82-
* **On initial render,** React will call the root component.
83-
* **For subsequent renders,** React will call the function component whose state update triggered the render.
82+
* **初回レンダー時**React はルート (root) コンポーネントを呼び出します。
83+
* **次回以降のレンダー**では、state の更新によってレンダーのトリガが起きた関数コンポーネントを、React がコールします。
8484

85-
This process is recursive: if the updated component returns some other component, React will render _that_ component next, and if that component also returns something, it will render _that_ component next, and so on. The process will continue until there are no more nested components and React knows exactly what should be displayed on screen.
85+
このプロセスは再帰的に発生します。更新されたコンポーネントが他のコンポーネントを返す場合、次に*その*コンポーネントを React がレンダーし、そのコンポーネントも何かコンポーネントを返す場合、*その*コンポーネントも次にレンダーし、といった具合に続きます。このプロセスは、ネストされたコンポーネントがなくなり、React が画面に表示されるべき内容を正確に把握するまで続きます。
8686

87-
In the following example, React will call `Gallery()` and `Image()` several times:
87+
次の例では、React `Gallery()` を呼び出した後、`Image()` を何度も呼び出します。
8888

8989
<Sandpack>
9090

@@ -124,36 +124,36 @@ img { margin: 0 10px 10px 0; }
124124

125125
</Sandpack>
126126

127-
* **During the initial render,** React will [create the DOM nodes](https://developer.mozilla.org/docs/Web/API/Document/createElement) for `<section>`, `<h1>`, and three `<img>` tags.
128-
* **During a re-render,** React will calculate which of their properties, if any, have changed since the previous render. It won't do anything with that information until the next step, the commit phase.
127+
* **初回レンダー時には**React `<section>``<h1>`、および 3 つの `<img>` タグの [DOM ノードを作成](https://developer.mozilla.org/docs/Web/API/Document/createElement)します。
128+
* **再レンダー時には**React は前回のレンダーからどの部分が変わったのか、あるいは変わらなかったのかを計算します。次のステップであるコミットフェーズまでこの情報は使われません。
129129

130130
<Pitfall>
131131

132-
Rendering must always be a [pure calculation](/learn/keeping-components-pure):
132+
レンダーは常に[純粋な計算](/learn/keeping-components-pure)であるべきです。
133133

134-
* **Same inputs, same output.** Given the same inputs, a component should always return the same JSX. (When someone orders a salad with tomatoes, they should not receive a salad with onions!)
135-
* **It minds its own business.** It should not change any objects or variables that existed before rendering. (One order should not change anyone else's order.)
134+
* **同じ入力には同じ出力**。同じ入力が与えられた場合、コンポーネントは常に同じ JSX を返す必要がある。(トマトサラダを注文した人がオニオンサラダを受け取ってはいけない!)
135+
* **自分の仕事に専念する**。レンダー前に存在したオブジェクトや変数を変更しない。(ある注文が他の誰かの注文を変更してはいけない。)
136136

137-
Otherwise, you can encounter confusing bugs and unpredictable behavior as your codebase grows in complexity. When developing in "Strict Mode", React calls each component's function twice, which can help surface mistakes caused by impure functions.
137+
さもないと、コードベースが複雑になるにつれて、混乱するバグや予測不能な挙動に遭遇することになります。"Strict Mode" で開発している場合、React は各コンポーネントの関数を 2 回呼び出し、純粋でない関数による誤りに気づきやすいようにしてくれます。
138138

139139
</Pitfall>
140140

141141
<DeepDive>
142142

143-
#### Optimizing performance {/*optimizing-performance*/}
143+
#### パフォーマンスの最適化 {/*optimizing-performance*/}
144144

145-
The default behavior of rendering all components nested within the updated component is not optimal for performance if the updated component is very high in the tree. If you run into a performance issue, there are several opt-in ways to solve it described in the [Performance](https://reactjs.org/docs/optimizing-performance.html) section. **Don't optimize prematurely!**
145+
更新されたコンポーネントがツリー内で非常に高い位置にある場合、その内部にネストされたすべてのコンポーネントを再レンダーするというデフォルトの挙動は、パフォーマンスにとって理想的ではありません。パフォーマンスの問題に遭遇した場合、[パフォーマンス](https://reactjs.org/docs/optimizing-performance.html)セクションで述べられているいくつかのオプトインによる解決方法があります。**最適化は急いでやってはいけません!**
146146

147147
</DeepDive>
148148

149-
## Step 3: React commits changes to the DOM {/*step-3-react-commits-changes-to-the-dom*/}
149+
## ステップ 3:React DOM への変更をコミットする {/*step-3-react-commits-changes-to-the-dom*/}
150150

151-
After rendering (calling) your components, React will modify the DOM.
151+
あなたのコンポーネントをレンダー(関数として呼び出し)した後、React DOM を変更します。
152152

153-
* **For the initial render,** React will use the [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API to put all the DOM nodes it has created on screen.
154-
* **For re-renders,** React will apply the minimal necessary operations (calculated while rendering!) to make the DOM match the latest rendering output.
153+
* **初回レンダー時には**React [`appendChild()`](https://developer.mozilla.org/docs/Web/API/Node/appendChild) DOM API を使用して、作成したすべての DOM ノードを画面に表示します。
154+
* **再レンダー時には**React は最新のレンダー出力に合わせて DOM を変更するため、必要な最小限の操作(レンダー中に計算されたもの!)を適用します。
155155

156-
**React only changes the DOM nodes if there's a difference between renders.** For example, here is a component that re-renders with different props passed from its parent every second. Notice how you can add some text into the `<input>`, updating its `value`, but the text doesn't disappear when the component re-renders:
156+
**React はレンダー間で違いがあった場合にのみ DOM ノードを変更します**。例えば、以下のコンポーネントは親から渡された異なる props で毎秒再レンダーされます。`<input>` にテキストを追加して `value` に変化があった場合でも、コンポーネントが再レンダーされたときにテキストが消えないことに注意してください:
157157

158158
<Sandpack>
159159

@@ -193,21 +193,21 @@ export default function App() {
193193

194194
</Sandpack>
195195

196-
This works because during this last step, React only updates the content of `<h1>` with the new `time`. It sees that the `<input>` appears in the JSX in the same place as last time, so React doesn't touch the `<input>`—or its `value`!
197-
## Epilogue: Browser paint {/*epilogue-browser-paint*/}
196+
これが動作するのは、最終ステップの部分で React は、新しい `time` を使って `<h1>` の中身だけを更新するからです。`<input>` JSX 内で前回と同じ場所にあるので、React `<input>` やその `value` に触れません!
197+
## エピローグ:ブラウザのペイント {/*epilogue-browser-paint*/}
198198

199-
After rendering is done and React updated the DOM, the browser will repaint the screen. Although this process is known as "browser rendering", we'll refer to it as "painting" to avoid confusion throughout the docs.
199+
レンダーが完了し、React DOM を更新した後、ブラウザは画面を再描画します。このプロセスは「ブラウザレンダリング」として知られていますが、ドキュメント全体での混乱を避けるために、我々は「ペイント」と呼ぶことにします。
200200

201-
<Illustration alt="A browser painting 'still life with card element'." src="/images/docs/illustrations/i_browser-paint.png" />
201+
<Illustration alt="ブラウザが「カード要素と静物画」をペイントしている" src="/images/docs/illustrations/i_browser-paint.png" />
202202

203203
<Recap>
204204

205-
* Any screen update in a React app happens in three steps:
206-
1. Trigger
207-
2. Render
208-
3. Commit
209-
* You can use Strict Mode to find mistakes in your components
210-
* React does not touch the DOM if the rendering result is the same as last time
205+
* React アプリでの画面更新は、以下の 3 つのステップで行われる:
206+
1. トリガ
207+
2. レンダー
208+
3. コミット
209+
* Strict Mode を使って、コンポーネントの間違いを発見できる。
210+
* レンダー結果が前回と同一である場合、React DOM を触らない。
211211

212212
</Recap>
213213

0 commit comments

Comments
 (0)