You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`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 によってサポートされていますが、新しいコードでの使用は推奨されません。
14
14
15
15
```js
16
16
classGreetingextendsPureComponent {
@@ -26,11 +26,11 @@ class Greeting extends PureComponent {
26
26
27
27
---
28
28
29
-
## Reference {/*reference*/}
29
+
## リファレンス {/*reference*/}
30
30
31
31
### `PureComponent` {/*purecomponent*/}
32
32
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` を継承します。
34
34
35
35
```js
36
36
import { PureComponent } from'react';
@@ -42,18 +42,17 @@ class Greeting extends PureComponent {
42
42
}
43
43
```
44
44
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)メソッドを定義することと同等です。
46
46
47
-
48
-
[See more examples below.](#usage)
47
+
[さらに例を見る](#usage)
49
48
50
49
---
51
50
52
-
## Usage {/*usage*/}
51
+
## 使用法 {/*usage*/}
53
52
54
-
### Skipping unnecessary re-renders for class components {/*skipping-unnecessary-re-renders-for-class-components*/}
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` を継承することにより、この挙動を有効化できます。
57
56
58
57
```js {1}
59
58
classGreetingextendsPureComponent {
@@ -63,9 +62,9 @@ class Greeting extends PureComponent {
63
62
}
64
63
```
65
64
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.
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):
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:
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)。
0 commit comments