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
Copy file name to clipboardExpand all lines: Framework/react-br.md
+34-34Lines changed: 34 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -67,9 +67,7 @@ class ExampleComponent extends React.Component {
67
67
68
68
`getSnapshotBeforeUpdate` é usado para substituir o `componentWillUpdate`, do qual é chamado depois do `update` mas antes do DOM atualizar para leitura o último dado do DOM.
69
69
70
-
## O conselho usado dos metodos do ciclos de vida no React V16
71
-
72
-
## The usage advice of Lifecycle methods in React V16
70
+
## O conselho usado nos métodos do ciclo de vida no React V16
73
71
74
72
```js
75
73
classExampleComponentextendsReact.Component {
@@ -79,23 +77,23 @@ class ExampleComponent extends React.Component {
79
77
// Porque a função é estática, você não pode acessar o `this`
80
78
// Se você precisar comparar `prevProps`, você precisa manter ele separado no `state`
@@ -104,13 +102,13 @@ class ExampleComponent extends React.Component {
104
102
105
103
# setState
106
104
107
-
`setState`is an API that is often used in React, but it has some problems that can lead to mistakes. The core reason is that the API is asynchronous.
105
+
`setState`é uma API que é frequentemente usada no React, mas ele tem alguns problemas que podem levar a erros. O centro das razões é que a API é assíncrona.
108
106
109
-
First, calling `setState`does not immediately cause a change to `state`, and if you call multiple`setState`at a time, the result may not be as you expect.
107
+
Primeiro, chamando `setState`não casa mudança imediata no `state`, e se você chamar multiplos`setState`de uma vez, o resultado pode não ser como o esperado.
110
108
111
109
```js
112
110
handle() {
113
-
//Initialize `count` to 0
111
+
//Iniciado o `count` em 0
114
112
console.log(this.state.count) // -> 0
115
113
this.setState({ count:this.state.count+1 })
116
114
this.setState({ count:this.state.count+1 })
@@ -119,9 +117,10 @@ handle() {
119
117
}
120
118
```
121
119
122
-
First, both prints are 0, because `setState` is an asynchronous API and will only execute after the sync code has finished running. The reason for `setState` is asynchronous is that `setState` may cause repainting of the DOM. If the call is repainted immediately after the call, the call will cause unnecessary performance loss. Designed to be asynchronous, you can put multiple calls into a queue and unify the update process when appropriate.
120
+
Primeiro, ambos os prints são 0, porque o `setState` é uma API assíncrona e irá apenas executar depois do código síncrono terminar sua execução. O motivo para o `setState` ser assíncrono é que `setState` pode causar repintar no DOM. Se a chamada repintar imediatamente depois da chamada, a chamada vai causar uma perca de performance desnecessária. Desenhando para ser assíncrono, você pode colocar multiplas chamadas dentro da fila e unificar os processos de atualização quando apropriado.
121
+
122
+
Segundo, apesar do `setState` ser chamado três vezes, o valor do `count` ainda é 1. Porque multiplas chamadas são fundidas em uma, o `state` só vai mudar quando a atualização terminar, e três chamadas são equivalente para o seguinte código.
123
123
124
-
Second, although `setState` is called three times, the value of `count` is still 1. Because multiple calls are merged into one, only `state` will change when the update ends, and three calls are equivalent to the following code.
125
124
126
125
```js
127
126
Object.assign(
@@ -132,7 +131,7 @@ Object.assign(
132
131
)
133
132
```
134
133
135
-
Of course, you can also call`setState`three times by the following way to make`count` 3
134
+
De fato, você pode também chamar`setState`três vezes da seguinte maneira para fazer`count` 3
136
135
137
136
```js
138
137
handle() {
@@ -142,7 +141,8 @@ handle() {
142
141
}
143
142
```
144
143
145
-
If you want to get the correct `state` after each call to `setState`, you can do it with the following code:
144
+
Se você quer acessar o `state` correto depois de cada chamada ao `setState`, você pode fazer isso com o seguinte código:
145
+
146
146
147
147
```js
148
148
handle() {
@@ -151,20 +151,20 @@ handle() {
151
151
})
152
152
}
153
153
```
154
-
# Redux Source Code Analysis
154
+
# Análise de código do Redux
155
155
156
-
Let's take a look at the`combineReducers`function first.
156
+
Vamos dar uma olhada na função`combineReducers`primeiro.
157
157
158
158
```js
159
-
//pass an object
159
+
//passe um objeto
160
160
exportdefaultfunctioncombineReducers(reducers) {
161
-
//get this object's keys
161
+
//capture as chaves desse objeto
162
162
constreducerKeys=Object.keys(reducers)
163
-
// reducers after filtering
163
+
// reducers depois filtrados
164
164
constfinalReducers= {}
165
-
//get the values corresponding to every key
166
-
//in dev environment, check if the value is undefined
167
-
//then put function type values into finalReducers
165
+
//obtenha os valores correspondentes para cada chave
166
+
//no ambiente de desenvolvimento, verifique se o valor é undefined
167
+
//então coloque os valores do tipo de função dentro do finalReducers
168
168
for (let i =0; i <reducerKeys.length; i++) {
169
169
constkey= reducerKeys[i]
170
170
@@ -178,25 +178,25 @@ export default function combineReducers(reducers) {
178
178
finalReducers[key] = reducers[key]
179
179
}
180
180
}
181
-
//get the keys of the reducers after filtering
181
+
//obtenha as chaves dos reducers depois de filtrado
182
182
constfinalReducerKeys=Object.keys(finalReducers)
183
183
184
-
//in dev environment check and save unexpected key to cache for warnings later
184
+
//no ambiente de desenvolvimento verifique e salvo as chaves inesperadas em cache para alertas futuros
185
185
let unexpectedKeyCache
186
186
if (process.env.NODE_ENV!=='production') {
187
187
unexpectedKeyCache = {}
188
188
}
189
189
190
190
let shapeAssertionError
191
191
try {
192
-
//explanations of the function is below
192
+
//explicações de funções estão abaixo
193
193
assertReducerShape(finalReducers)
194
194
} catch (e) {
195
195
shapeAssertionError = e
196
196
}
197
-
// combineReducers returns another function, which is reducer after merging
198
-
//this function returns the root state
199
-
//also notice a closure is used here. The function uses some outside properties
197
+
// combineReducers retorna outra função, que é reduzido depois de fundido
198
+
//essa função retorna o state raiz
199
+
//também percena que um encerramento é usado aqui. A função usa algumas propriedades externas
0 commit comments