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
* add react without es6 pt-br translation
* Apply suggestions from code review to fix Portuguese typos
Co-Authored-By: gutofoletto <[email protected]>
* changed wikipedia link to point to Portuguese website
Co-Authored-By: gutofoletto <[email protected]>
* Apply suggestions from Portuguese review
Co-Authored-By: gutofoletto <[email protected]>
* changed the word 'estado' to 'state'
Co-Authored-By: gutofoletto <[email protected]>
With functions and ES6 classes `defaultProps`is defined as a property on the component itself:
33
+
Com funções e classes ES6, `defaultProps`é definido como uma propriedade do próprio componente:
34
34
35
35
```javascript
36
36
classGreetingextendsReact.Component {
@@ -42,7 +42,7 @@ Greeting.defaultProps = {
42
42
};
43
43
```
44
44
45
-
With`createReactClass()`, you need to define `getDefaultProps()`as a function on the passed object:
45
+
Com`createReactClass()`, você precisa definir `getDefaultProps()`como uma função no objeto que é passado como parâmetro:
46
46
47
47
```javascript
48
48
var Greeting =createReactClass({
@@ -57,9 +57,9 @@ var Greeting = createReactClass({
57
57
});
58
58
```
59
59
60
-
## Setting the Initial State {#setting-the-initial-state}
60
+
## Configurando o State Inicial {#setting-the-initial-state}
61
61
62
-
In ES6 classes, you can define the initial state by assigning `this.state`in the constructor:
62
+
Em classes ES6, você pode definir o state inicial ao definir `this.state`no construtor:
63
63
64
64
```javascript
65
65
classCounterextendsReact.Component {
@@ -71,7 +71,7 @@ class Counter extends React.Component {
71
71
}
72
72
```
73
73
74
-
With`createReactClass()`, you have to provide a separate `getInitialState`method that returns the initial state:
74
+
Com`createReactClass()`, você deve passar um método `getInitialState`que retorna o state inicial:
75
75
76
76
```javascript
77
77
var Counter =createReactClass({
@@ -84,14 +84,14 @@ var Counter = createReactClass({
84
84
85
85
## Autobinding {#autobinding}
86
86
87
-
In React components declared as ES6 classes, methods follow the same semantics as regular ES6 classes. This means that they don't automatically bind `this`to the instance. You'll have to explicitly use`.bind(this)`in the constructor:
87
+
Em componentes React declarados como classes ES6, métodos seguem a mesma semântica que classes ES6 regulares. Isso significa que elas não fazem bind do `this`da instância. Você terá que explicitamente usar`.bind(this)`no construtor:
88
88
89
89
```javascript
90
90
classSayHelloextendsReact.Component {
91
91
constructor(props) {
92
92
super(props);
93
93
this.state= {message:'Hello!'};
94
-
//This line is important!
94
+
//Esta linha é importante!
95
95
this.handleClick=this.handleClick.bind(this);
96
96
}
97
97
@@ -100,7 +100,7 @@ class SayHello extends React.Component {
100
100
}
101
101
102
102
render() {
103
-
//Because `this.handleClick` is bound, we can use it as an event handler.
103
+
//Devido `this.handleClick` ter sido amarrado, podemos usá-lo como um controlador de evento.
104
104
return (
105
105
<button onClick={this.handleClick}>
106
106
Say hello
@@ -110,7 +110,7 @@ class SayHello extends React.Component {
110
110
}
111
111
```
112
112
113
-
With`createReactClass()`, this is not necessary because it binds all methods:
113
+
Com`createReactClass()`, isso não é necessário por que ele faz bind de todos os métodos:
114
114
115
115
```javascript
116
116
var SayHello =createReactClass({
@@ -132,9 +132,9 @@ var SayHello = createReactClass({
132
132
});
133
133
```
134
134
135
-
This means writing ES6 classes comes with a little more boilerplate code for event handlers, but the upside is slightly better performance in large applications.
135
+
Isso significa que escrever classes ES6 necessita um pouco mais de código boilerplate para controladores de eventos. Por outro lado, é levemente mais performático em aplicações de larga escala.
136
136
137
-
If the boilerplate code is too unattractive to you, you may enable the **experimental**[Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/)syntax proposal with Babel:
137
+
Se você acha que código boilerplate pouco atraente, você pode ativar a proposta de [Class Properties](https://babeljs.io/docs/plugins/transform-class-properties/)**experimentais** com Babel:
138
138
139
139
140
140
```javascript
@@ -143,8 +143,8 @@ class SayHello extends React.Component {
143
143
super(props);
144
144
this.state= {message:'Hello!'};
145
145
}
146
-
//WARNING: this syntax is experimental!
147
-
//Using an arrow here binds the method:
146
+
//AVISO: essa sintaxe é experimental!
147
+
//Usar uma arrow function aqui já faz bind do método
148
148
handleClick= () => {
149
149
alert(this.state.message);
150
150
}
@@ -159,27 +159,27 @@ class SayHello extends React.Component {
159
159
}
160
160
```
161
161
162
-
Please note that the syntax above is **experimental**and the syntax may change, or the proposal might not make it into the language.
162
+
Por favor, notem que a sintaxe acima é **experimental**e que a sintaxe pode mudar ou ainda, a proposta pode não ser implementada na linguagem.
163
163
164
-
If you'd rather play it safe, you have a few options:
164
+
Se você prefere jogar seguro, você tem algumas opções:
165
165
166
-
*Bind methods in the constructor.
167
-
*Use arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`.
168
-
*Keep using`createReactClass`.
166
+
*Fazer bind do método no construtor.
167
+
*Usar arrow functions, e.g. `onClick={(e) => this.handleClick(e)}`.
168
+
*Continuar usando`createReactClass`.
169
169
170
170
## Mixins {#mixins}
171
171
172
-
>**Note:**
172
+
>**Notas:**
173
173
>
174
-
>ES6 launched without any mixin support. Therefore, there is no support for mixins when you use React with ES6 classes.
174
+
>ES6 foi lançado sem suporte a mixins. Portanto, não há suporte para mixins quando você usar React com classes ES6.
175
175
>
176
-
>**We also found numerous issues in codebases using mixins, [and don't recommend using them in the new code](/blog/2016/07/13/mixins-considered-harmful.html).**
176
+
>**Nós também descobrimos inúmeros problemas na base de código usando mixins, [e não recomendamos usar em novos códigos](/blog/2016/07/13/mixins-considered-harmful.html).**
177
177
>
178
-
>This section exists only for the reference.
178
+
>Esta seção existe somente para referência.
179
179
180
-
Sometimes very different components may share some common functionality. These are sometimes called[cross-cutting concerns](https://en.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass`lets you use a legacy `mixins`system for that.
180
+
Algumas vezes, componentes muito diferentes podem compartilhar alguma funcionalidade. Chamamos estes casos de[cross-cutting concerns](https://pt.wikipedia.org/wiki/Cross-cutting_concern). `createReactClass`permite que você use um sistema legado de `mixins`para isso.
181
181
182
-
One common use case is a component wanting to update itself on a time interval. It's easy to use `setInterval()`, but it's important to cancel your interval when you don't need it anymore to save memory. React provides[lifecycle methods](/docs/react-component.html#the-component-lifecycle)that let you know when a component is about to be created or destroyed. Let's create a simple mixin that uses these methods to provide an easy `setInterval()`function that will automatically get cleaned up when your component is destroyed.
182
+
Um caso de uso comum é um componente que quer se atualizar em um intervalo de tempo. É fácil de usar o `setInterval()`, mas é importante do cancelar o intervalo quando você não precisa mais dele para economizar memória. React fornece[lifecycle methods](/docs/react-component.html#the-component-lifecycle)que permitem que você saiba quando um componente está prestes a ser criado ou destruído. Vamos criar um *mixin* simples que usa esses métodos para fornecer uma funcionalidade fácil de `setInterval()`que será limpa automaticamente quando seu componente for destruído.
183
183
184
184
```javascript
185
185
var SetIntervalMixin = {
@@ -197,20 +197,20 @@ var SetIntervalMixin = {
197
197
var createReactClass =require('create-react-class');
198
198
199
199
var TickTock =createReactClass({
200
-
mixins: [SetIntervalMixin], // Use the mixin
200
+
mixins: [SetIntervalMixin], // Use o mixin
201
201
getInitialState:function() {
202
202
return {seconds:0};
203
203
},
204
204
componentDidMount:function() {
205
-
this.setInterval(this.tick, 1000); //Call a method on the mixin
205
+
this.setInterval(this.tick, 1000); //Chamada de um método no mixin
206
206
},
207
207
tick:function() {
208
208
this.setState({seconds:this.state.seconds+1});
209
209
},
210
210
render:function() {
211
211
return (
212
212
<p>
213
-
React has been running for{this.state.seconds} seconds.
213
+
React está rodando por {this.state.seconds} segundos.
214
214
</p>
215
215
);
216
216
}
@@ -222,4 +222,4 @@ ReactDOM.render(
222
222
);
223
223
```
224
224
225
-
If a component is using multiple mixins and several mixins define the same lifecycle method (i.e. several mixins want to do some cleanup when the component is destroyed), all of the lifecycle methods are guaranteed to be called. Methods defined on mixins run in the order mixins were listed, followed by a method call on the component.
225
+
Se um componente está usando múltiplos mixins e diversos desses mixins definem o mesmo lifecycle method (por ex. diversos mixins querem fazer uma limpeza quando um componente é destruído), todos os lifecycle methods terão garantia de serem chamados. Métodos definidos em um mixin são executados na ordem em que foram listados, seguidos por uma chamada de método no componente.
0 commit comments