Skip to content

Commit 0998fde

Browse files
authored
Merge pull request #692 from reactjs/tr/PureComponent
Translate "PureComponent"
2 parents e0686d4 + 0561351 commit 0998fde

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

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

+18-18
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ title: PureComponent
44

55
<Pitfall>
66

7-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
7+
クラスの代わりに関数でコンポーネントを定義することを推奨します。[移行方法はこちら](#alternatives)
88

99
</Pitfall>
1010

1111
<Intro>
1212

13-
`PureComponent` is similar to [`Component`](/reference/react/Component) but it skips re-renders for same props and state. Class components are still supported by React, but we don't recommend using them in new code.
13+
`PureComponent` [`Component`](/reference/react/Component) と似ていますが、同じ props state に対しては再レンダーをスキップします。クラスコンポーネントはまだ React によってサポートされていますが、新しいコードでの使用は推奨されません。
1414

1515
```js
1616
class Greeting extends PureComponent {
@@ -26,11 +26,11 @@ class Greeting extends PureComponent {
2626

2727
---
2828

29-
## Reference {/*reference*/}
29+
## リファレンス {/*reference*/}
3030

3131
### `PureComponent` {/*purecomponent*/}
3232

33-
To skip re-rendering a class component for same props and state, extend `PureComponent` instead of [`Component`:](/reference/react/Component)
33+
同じ props state に対してクラスコンポーネントの再レンダーをスキップしたい場合、[`Component`](/reference/react/Component) の代わりに `PureComponent` を継承します。
3434

3535
```js
3636
import { PureComponent } from 'react';
@@ -42,18 +42,17 @@ class Greeting extends PureComponent {
4242
}
4343
```
4444

45-
`PureComponent` is a subclass of `Component` and supports [all the `Component` APIs.](/reference/react/Component#reference) Extending `PureComponent` is equivalent to defining a custom [`shouldComponentUpdate`](/reference/react/Component#shouldcomponentupdate) method that shallowly compares props and state.
45+
`PureComponent` `Component` のサブクラスであり、[すべての `Component` API](/reference/react/Component#reference) をサポートしています。`PureComponent` を拡張することは、props と state を浅く比較するカスタムの [`shouldComponentUpdate`](/reference/react/Component#shouldcomponentupdate) メソッドを定義することと同等です。
4646

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

5049
---
5150

52-
## Usage {/*usage*/}
51+
## 使用法 {/*usage*/}
5352

54-
### Skipping unnecessary re-renders for class components {/*skipping-unnecessary-re-renders-for-class-components*/}
53+
### クラスコンポーネントの不要な再レンダーをスキップする {/*skipping-unnecessary-re-renders-for-class-components*/}
5554

56-
React normally re-renders a component whenever its parent re-renders. As an optimization, you can create a component that React will not re-render when its parent re-renders so long as its new props and state are the same as the old props and state. [Class components](/reference/react/Component) can opt into this behavior by extending `PureComponent`:
55+
React は通常、親が再レンダーされるたびにコンポーネントを再レンダーします。最適化として、新しい props state が古い props state と同じである限り、親が再レンダーされても React が再レンダーを行わない、というコンポーネントを作成することができます。[クラスコンポーネント](/reference/react/Component)では、`PureComponent` を継承することにより、この挙動を有効化できます。
5756

5857
```js {1}
5958
class Greeting extends PureComponent {
@@ -63,9 +62,9 @@ class Greeting extends PureComponent {
6362
}
6463
```
6564

66-
A React component should always have [pure rendering logic.](/learn/keeping-components-pure) This means that it must return the same output if its props, state, and context haven't changed. By using `PureComponent`, you are telling React that your component complies with this requirement, so React doesn't need to re-render as long as its props and state haven't changed. However, your component will still re-render if a context that it's using changes.
65+
React コンポーネントは常に[純粋なレンダーロジックを持つべきです](/learn/keeping-components-pure)。これはすなわち、その propsstate、コンテクストが変わらない場合は、常に同じ出力を返す必要がある、という意味です。`PureComponent` を使用することで、あなたのコンポーネントがこの要件を満たしていると React に伝えることができ、そのため React props state が変わらない限り再レンダーする必要がないと判断します。ただし、使用しているコンテクストが変更された場合、コンポーネントは再レンダーされます。
6766

68-
In this example, notice that the `Greeting` component re-renders whenever `name` is changed (because that's one of its props), but not when `address` is changed (because it's not passed to `Greeting` as a prop):
67+
以下の例で、`name` が変更されるたびに `Greeting` コンポーネントが再レンダーされる(`name` props として渡されているため)が、`address` が変更されても再レンダーされない(`Greeting` に props として渡されていないため)ことに注目してください。
6968

7069
<Sandpack>
7170

@@ -109,17 +108,18 @@ label {
109108

110109
<Pitfall>
111110

112-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
111+
クラスの代わりに関数でコンポーネントを定義することを推奨します。[移行方法はこちら](#alternatives)
112+
113113

114114
</Pitfall>
115115

116116
---
117117

118-
## Alternatives {/*alternatives*/}
118+
## 代替手段 {/*alternatives*/}
119119

120-
### Migrating from a `PureComponent` class component to a function {/*migrating-from-a-purecomponent-class-component-to-a-function*/}
120+
### `PureComponent` クラスのコンポーネントから関数コンポーネントへの移行 {/*migrating-from-a-purecomponent-class-component-to-a-function*/}
121121

122-
We recommend using function components instead of [class components](/reference/react/Component) in new code. If you have some existing class components using `PureComponent`, here is how you can convert them. This is the original code:
122+
新しいコードでは、[クラスコンポーネント](/reference/react/Component)の代わりに関数コンポーネントを使用することを推奨します。以下では、既存の `PureComponent` を使用したクラスコンポーネントがある場合、どのように移行するかを説明します。こちらが元のコードです。
123123

124124
<Sandpack>
125125

@@ -161,7 +161,7 @@ label {
161161

162162
</Sandpack>
163163

164-
When you [convert this component from a class to a function,](/reference/react/Component#alternatives) wrap it in [`memo`:](/reference/react/memo)
164+
このコンポーネントを[クラスから関数に移行](/reference/react/Component#alternatives)したい場合は、[`memo`](/reference/react/memo) でラップしてください。
165165

166166
<Sandpack>
167167

@@ -203,6 +203,6 @@ label {
203203

204204
<Note>
205205

206-
Unlike `PureComponent`, [`memo`](/reference/react/memo) does not compare the new and the old state. In function components, calling the [`set` function](/reference/react/useState#setstate) with the same state [already prevents re-renders by default,](/reference/react/memo#updating-a-memoized-component-using-state) even without `memo`.
206+
`PureComponent` とは異なり、[`memo`](/reference/react/memo) は新旧の state を比較しません。関数コンポーネントでは、同一の state 値で [`set` 関数](/reference/react/useState#setstate)を呼び出した場合、`memo` がなくても[デフォルトで再レンダーが防止されます](/reference/react/memo#updating-a-memoized-component-using-state)
207207

208208
</Note>

0 commit comments

Comments
 (0)