Skip to content

Commit db43783

Browse files
committed
Translate PureComponent.md to pt-br
1 parent 7148d38 commit db43783

File tree

1 file changed

+33
-33
lines changed

1 file changed

+33
-33
lines changed

src/content/reference/react/PureComponent.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ title: PureComponent
44

55
<Pitfall>
66

7-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
7+
Recomendamos definir componentes como funções em vez de classes. [Veja como migrar.](#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` é semelhante a [`Component`](/reference/react/Component), mas ignora re-renderizações para as mesmas props e estado. Os componentes de classe ainda são suportados pelo React, mas não recomendamos o uso deles em novo código.
1414

1515
```js
1616
class Greeting extends PureComponent {
1717
render() {
18-
return <h1>Hello, {this.props.name}!</h1>;
18+
return <h1>Olá, {this.props.name}!</h1>;
1919
}
2020
}
2121
```
@@ -26,46 +26,46 @@ class Greeting extends PureComponent {
2626

2727
---
2828

29-
## Reference {/*reference*/}
29+
## Referência {/*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+
Para pular a re-renderização de um componente de classe para as mesmas props e estado, estenda `PureComponent` em vez de [`Component`:](/reference/react/Component)
3434

3535
```js
3636
import { PureComponent } from 'react';
3737

3838
class Greeting extends PureComponent {
3939
render() {
40-
return <h1>Hello, {this.props.name}!</h1>;
40+
return <h1>Olá, {this.props.name}!</h1>;
4141
}
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` é uma subclasse de `Component` e suporta [todas as APIs de `Component`.](/reference/react/Component#reference) Estender `PureComponent` é equivalente a definir um método customizado [`shouldComponentUpdate`](/reference/react/Component#shouldcomponentupdate) que compara superficialmente props e estado.
4646

4747

48-
[See more examples below.](#usage)
48+
[Veja mais exemplos abaixo.](#usage)
4949

5050
---
5151

52-
## Usage {/*usage*/}
52+
## Uso {/*usage*/}
5353

54-
### Skipping unnecessary re-renders for class components {/*skipping-unnecessary-re-renders-for-class-components*/}
54+
### Ignorando re-renderizações desnecessárias para componentes de classe {/*skipping-unnecessary-re-renders-for-class-components*/}
5555

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`:
56+
O React normalmente re-renderiza um componente sempre que seu pai re-renderiza. Como uma otimização, você pode criar um componente que o React não re-renderiza quando seu pai re-renderiza, desde que suas novas props e estado sejam iguais às antigas props e estado. [Os componentes de classe](/reference/react/Component) podem optar por esse comportamento estendendo `PureComponent`:
5757

5858
```js {1}
5959
class Greeting extends PureComponent {
6060
render() {
61-
return <h1>Hello, {this.props.name}!</h1>;
61+
return <h1>Olá, {this.props.name}!</h1>;
6262
}
6363
}
6464
```
6565

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.
66+
Um componente React deve sempre ter [lógica de renderização pura.](/learn/keeping-components-pure) Isso significa que ele deve retornar a mesma saída se suas props, estado e contexto não tiverem mudado. Ao usar `PureComponent`, você está dizendo ao React que seu componente cumpre esse requisito, para que o React não precise re-renderizar enquanto suas props e estado não mudarem. No entanto, seu componente ainda re-renderizará se um contexto que ele está usando mudar.
6767

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):
68+
Neste exemplo, note que o componente `Greeting` re-renderiza sempre que `name` é alterado (porque essa é uma de suas props), mas não quando `address` é alterado (porque não é passado para `Greeting` como uma prop):
6969

7070
<Sandpack>
7171

@@ -74,8 +74,8 @@ import { PureComponent, useState } from 'react';
7474

7575
class Greeting extends PureComponent {
7676
render() {
77-
console.log("Greeting was rendered at", new Date().toLocaleTimeString());
78-
return <h3>Hello{this.props.name && ', '}{this.props.name}!</h3>;
77+
console.log("Greeting foi renderizado em", new Date().toLocaleTimeString());
78+
return <h3>Olá{name && ', '}{this.props.name}!</h3>;
7979
}
8080
}
8181

@@ -85,11 +85,11 @@ export default function MyApp() {
8585
return (
8686
<>
8787
<label>
88-
Name{': '}
88+
Nome{': '}
8989
<input value={name} onChange={e => setName(e.target.value)} />
9090
</label>
9191
<label>
92-
Address{': '}
92+
Endereço{': '}
9393
<input value={address} onChange={e => setAddress(e.target.value)} />
9494
</label>
9595
<Greeting name={name} />
@@ -109,17 +109,17 @@ label {
109109

110110
<Pitfall>
111111

112-
We recommend defining components as functions instead of classes. [See how to migrate.](#alternatives)
112+
Recomendamos definir componentes como funções em vez de classes. [Veja como migrar.](#alternatives)
113113

114114
</Pitfall>
115115

116116
---
117117

118-
## Alternatives {/*alternatives*/}
118+
## Alternativas {/*alternatives*/}
119119

120-
### Migrating from a `PureComponent` class component to a function {/*migrating-from-a-purecomponent-class-component-to-a-function*/}
120+
### Migrando de um componente de classe `PureComponent` para uma função {/*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+
Recomendamos usar componentes de função em vez de [componentes de classe](/reference/react/Component) em novo código. Se você tiver alguns componentes de classe existentes usando `PureComponent`, aqui está como você pode convertê-los. Este é o código original:
123123

124124
<Sandpack>
125125

@@ -128,8 +128,8 @@ import { PureComponent, useState } from 'react';
128128

129129
class Greeting extends PureComponent {
130130
render() {
131-
console.log("Greeting was rendered at", new Date().toLocaleTimeString());
132-
return <h3>Hello{this.props.name && ', '}{this.props.name}!</h3>;
131+
console.log("Greeting foi renderizado em", new Date().toLocaleTimeString());
132+
return <h3>Olá{name && ', '}{this.props.name}!</h3>;
133133
}
134134
}
135135

@@ -139,11 +139,11 @@ export default function MyApp() {
139139
return (
140140
<>
141141
<label>
142-
Name{': '}
142+
Nome{': '}
143143
<input value={name} onChange={e => setName(e.target.value)} />
144144
</label>
145145
<label>
146-
Address{': '}
146+
Endereço{': '}
147147
<input value={address} onChange={e => setAddress(e.target.value)} />
148148
</label>
149149
<Greeting name={name} />
@@ -161,16 +161,16 @@ 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+
Quando você [converter este componente de uma classe para uma função,](/reference/react/Component#alternatives) encapsule-o em [`memo`:](/reference/react/memo)
165165

166166
<Sandpack>
167167

168168
```js
169169
import { memo, useState } from 'react';
170170

171171
const Greeting = memo(function Greeting({ name }) {
172-
console.log("Greeting was rendered at", new Date().toLocaleTimeString());
173-
return <h3>Hello{name && ', '}{name}!</h3>;
172+
console.log("Greeting foi renderizado em", new Date().toLocaleTimeString());
173+
return <h3>Olá{name && ', '}{name}!</h3>;
174174
});
175175

176176
export default function MyApp() {
@@ -179,11 +179,11 @@ export default function MyApp() {
179179
return (
180180
<>
181181
<label>
182-
Name{': '}
182+
Nome{': '}
183183
<input value={name} onChange={e => setName(e.target.value)} />
184184
</label>
185185
<label>
186-
Address{': '}
186+
Endereço{': '}
187187
<input value={address} onChange={e => setAddress(e.target.value)} />
188188
</label>
189189
<Greeting name={name} />
@@ -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+
Diferente de `PureComponent`, [`memo`](/reference/react/memo) não compara o novo e o antigo estado. Em componentes de função, chamar a [`função set`](/reference/react/useState#setstate) com o mesmo estado [já previne re-renderizações por padrão,](/reference/react/memo#updating-a-memoized-component-using-state) mesmo sem `memo`.
207207

208-
</Note>
208+
</Note>

0 commit comments

Comments
 (0)