Skip to content

Commit 4efc4b7

Browse files
author
Jhon Mike
authored
Merge pull request reactjs#141 from reactjs/sync-8803c637
Sync with reactjs.org @ 8803c63
2 parents a401fe7 + 35aa902 commit 4efc4b7

File tree

3 files changed

+58
-49
lines changed

3 files changed

+58
-49
lines changed

content/docs/code-splitting.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ import("./math").then(math => {
102102
103103
When Webpack comes across this syntax, it automatically starts code-splitting
104104
your app. If you're using Create React App, this is already configured for you
105-
and you can [start using it](https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#code-splitting) immediately. It's also supported
105+
and you can [start using it](https://facebook.github.io/create-react-app/docs/code-splitting) immediately. It's also supported
106106
out of the box in [Next.js](https://github.com/zeit/next.js/#dynamic-import).
107107

108108
If you're setting up Webpack yourself, you'll probably want to read Webpack's

content/languages.yml

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Status enums indicate what percentage of "core" content has been translated:
2-
# 0: Incomplete (049%)
3-
# 1: Partially complete (50–94%)
4-
# 2: Complete (95–100%)
2+
# 0: Incomplete (0-49%)
3+
# 1: Partially complete (50-99%)
4+
# 2: Complete (100%)
55

66
- name: English
77
translated_name: English
@@ -27,6 +27,10 @@
2727
translated_name: Deutsch
2828
code: de
2929
status: 0
30+
- name: Greek
31+
translated_name: Ελληνικά
32+
code: el
33+
status: 0
3034
- name: Spanish
3135
translated_name: Español
3236
code: es
@@ -38,6 +42,10 @@
3842
- name: French
3943
translated_name: Français
4044
code: fr
45+
status: 1
46+
- name: Gujarati
47+
translated_name: ગુજરાતી
48+
code: gu
4149
status: 0
4250
- name: Hebrew
4351
translated_name: עברית
@@ -62,11 +70,23 @@
6270
- name: Japanese
6371
translated_name: 日本語
6472
code: ja
65-
status: 1
73+
status: 2
74+
- name: Central Khmer
75+
translated_name: ភាសាខ្មែរ
76+
code: km
77+
status: 0
6678
- name: Korean
6779
translated_name: 한국어
6880
code: ko
6981
status: 0
82+
- name: Kurdish
83+
translated_name: کوردی‎
84+
code: ku
85+
status: 0
86+
- name: Lithuanian
87+
translated_name: Lietuvių kalba
88+
code: lt
89+
status: 0
7090
- name: Malayalam
7191
translated_name: മലയാളം
7292
code: ml
@@ -98,7 +118,7 @@
98118
- name: Russian
99119
translated_name: Русский
100120
code: ru
101-
status: 0
121+
status: 1
102122
- name: Sinhala
103123
translated_name: සිංහල
104124
code: si
@@ -107,13 +127,21 @@
107127
translated_name: தமிழ்
108128
code: ta
109129
status: 0
130+
- name: Telugu
131+
translated_name: తెలుగు
132+
code: te
133+
status: 0
110134
- name: Turkish
111135
translated_name: Türkçe
112136
code: tr
113137
status: 0
114138
- name: Ukrainian
115139
translated_name: Українська
116140
code: uk
141+
status: 1
142+
- name: Urdu
143+
translated_name: اردو
144+
code: ur
117145
status: 0
118146
- name: Uzbek
119147
translated_name: Oʻzbekcha
@@ -126,7 +154,7 @@
126154
- name: Simplified Chinese
127155
translated_name: 简体中文
128156
code: zh-hans
129-
status: 0
157+
status: 1
130158
- name: Traditional Chinese
131159
translated_name: 繁體中文
132160
code: zh-hant

content/tutorial/tutorial.md

Lines changed: 23 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ O tutorial está dividido em várias seções:
3131

3232
Você não precisa completar todas as seções de uma vez para entender tudo que o tutorial tem a oferecer. Tente chegar o mais longe possível, mesmo que seja uma ou duas seções.
3333

34-
Não há problema em copiar e colar o código enquanto você acompanha o tutorial. Mas, recomendamos que você o digite à mão. Isso ajudará você a desenvolver uma memória muscular e ter um entendimento mais forte.
35-
3634
### O que estamos construindo? {#what-are-we-building}
3735

3836
Neste tutorial, mostraremos como criar um jogo interativo de jogo-da-velha com React.
@@ -190,6 +188,8 @@ O componente Square renderiza um único `<button>` e o Board renderiza 9 squares
190188

191189
Para aquecer, vamos tentar passar alguns dados do nosso componente Board para o nosso componente Square.
192190

191+
É altamente recomendável digitar o código manualmente, enquanto você está trabalhando no tutorial e não usando copiar/colar. Isso ajudará você a desenvolver a memória muscular e um melhor entendimento.
192+
193193
No método `renderSquare` do Board, altere o código para passar um prop chamado `value` para o Square:
194194

195195
```js{3}
@@ -242,7 +242,7 @@ class Square extends React.Component {
242242
}
243243
```
244244

245-
Se clicarmos em um quadrado agora, devemos receber um alerta em nosso navegador.
245+
Se você clicar em um quadrado agora, deverá ver um alerta no seu navegador.
246246

247247
>Nota
248248
>
@@ -260,7 +260,7 @@ Se clicarmos em um quadrado agora, devemos receber um alerta em nosso navegador.
260260
>}
261261
>```
262262
>
263-
>Note que com `onClick = {() => alert ('click')}`, estamos passando *uma função* como prop `onClick`. Ela é acionada após um clique. Esquecer o `() =>` e escrever somente `onClick = {alert ('click')}` é um erro comum, e dispararia o alerta toda vez que o componente fosse renderizado novamente.
263+
>Note que com `onClick = {() => alert ('click')}`, estamos passando *uma função* como prop `onClick`. O React chamará essa função depois de um clique. Esquecendo `() =>` e escrevendo somente `onClick = {alert ('click')}` é um erro comum, e dispararia o alerta toda vez que o componente fosse renderizado novamente.
264264
265265
Como próximo passo, queremos que o componente Square "lembre" que foi clicado e preencha com um "X". Para "lembrar" as coisas, os componentes usam o **estado (_state_)**.
266266
@@ -294,8 +294,8 @@ class Square extends React.Component {
294294
Agora vamos mudar o método `render` do componente Square para exibir o valor do estado (_state_) atual quando clicado:
295295

296296
* Substitua `this.props.value` por` this.state.value` dentro da tag `<button>`.
297-
* Substitua o manipulador de eventos `() => alert ()` por `() => this.setState ({value: 'X'})`.
298-
* Coloque `className` e` onClick` em linhas separadas para melhor legibilidade.
297+
* Substitua o `onClick={...}` event handler por `onClick={() => this.setState({value: 'X'})}`.
298+
* Coloque `className` e` onClick` props em linhas separadas para melhor legibilidade.
299299

300300
Após estas mudanças, a tag `<button>` que é retornada pelo método `render` do Square deve se parecer com isto:
301301

@@ -356,7 +356,9 @@ We may think that Board should just ask each Square for the Square's state. Alth
356356

357357
**To collect data from multiple children, or to have two child components communicate with each other, you need to declare the shared state in their parent component instead. The parent component can pass the state back down to the children by using props; this keeps the child components in sync with each other and with the parent component.**
358358

359-
Lifting state into a parent component is common when React components are refactored -- let's take this opportunity to try it out. We'll add a constructor to the Board and set the Board's initial state to contain an array with 9 nulls. These 9 nulls correspond to the 9 squares:
359+
Lifting state into a parent component is common when React components are refactored -- let's take this opportunity to try it out.
360+
361+
Add a constructor to the Board and set the Board's initial state to contain an array of 9 nulls corresponding to the 9 squares:
360362

361363
```javascript{2-7}
362364
class Board extends React.Component {
@@ -370,35 +372,9 @@ class Board extends React.Component {
370372
renderSquare(i) {
371373
return <Square value={i} />;
372374
}
373-
374-
render() {
375-
const status = 'Next player: X';
376-
377-
return (
378-
<div>
379-
<div className="status">{status}</div>
380-
<div className="board-row">
381-
{this.renderSquare(0)}
382-
{this.renderSquare(1)}
383-
{this.renderSquare(2)}
384-
</div>
385-
<div className="board-row">
386-
{this.renderSquare(3)}
387-
{this.renderSquare(4)}
388-
{this.renderSquare(5)}
389-
</div>
390-
<div className="board-row">
391-
{this.renderSquare(6)}
392-
{this.renderSquare(7)}
393-
{this.renderSquare(8)}
394-
</div>
395-
</div>
396-
);
397-
}
398-
}
399375
```
400376

401-
When we fill the board in later, the board will look something like this:
377+
When we fill the board in later, the `this.state.squares` array will look something like this:
402378

403379
```javascript
404380
[
@@ -432,7 +408,7 @@ Each Square will now receive a `value` prop that will either be `'X'`, `'O'`, or
432408

433409
Next, we need to change what happens when a Square is clicked. The Board component now maintains which squares are filled. We need to create a way for the Square to update the Board's state. Since state is considered to be private to a component that defines it, we cannot update the Board's state directly from Square.
434410

435-
To maintain the Board's state's privacy, we'll pass down a function from the Board to the Square. This function will get called when a Square is clicked. We'll change the `renderSquare` method in Board to:
411+
Instead, we'll pass down a function from the Board to the Square, and we'll have Square call that function when a square is clicked. We'll change the `renderSquare` method in Board to:
436412

437413
```javascript{5}
438414
renderSquare(i) {
@@ -478,11 +454,11 @@ When a Square is clicked, the `onClick` function provided by the Board is called
478454
2. When the button is clicked, React will call the `onClick` event handler that is defined in Square's `render()` method.
479455
3. This event handler calls `this.props.onClick()`. The Square's `onClick` prop was specified by the Board.
480456
4. Since the Board passed `onClick={() => this.handleClick(i)}` to Square, the Square calls `this.handleClick(i)` when clicked.
481-
5. We have not defined the `handleClick()` method yet, so our code crashes.
457+
5. We have not defined the `handleClick()` method yet, so our code crashes. If you click a square now, you should see a red error screen saying something like "this.handleClick is not a function".
482458

483459
>Note
484460
>
485-
>The DOM `<button>` element's `onClick` attribute has a special meaning to React because it is a built-in component. For custom components like Square, the naming is up to you. We could name the Square's `onClick` prop or Board's `handleClick` method differently. In React, however, it is a convention to use `on[Event]` names for props which represent events and `handle[Event]` for the methods which handle the events.
461+
>The DOM `<button>` element's `onClick` attribute has a special meaning to React because it is a built-in component. For custom components like Square, the naming is up to you. We could give any name to the Square's `onClick` prop or Board's `handleClick` method, and the code would work the same. In React, it's conventional to use `on[Event]` names for props which represent events and `handle[Event]` for the methods which handle the events.
486462
487463
When we try to click a Square, we should get an error because we haven't defined `handleClick` yet. We'll now add `handleClick` to the Board class:
488464

@@ -539,7 +515,7 @@ class Board extends React.Component {
539515

540516
**[View the full code at this point](https://codepen.io/gaearon/pen/ybbQJX?editors=0010)**
541517

542-
After these changes, we're again able to click on the Squares to fill them. However, now the state is stored in the Board component instead of the individual Square components. When the Board's state changes, the Square components re-render automatically. Keeping the state of all squares in the Board component will allow it to determine the winner in the future.
518+
After these changes, we're again able to click on the Squares to fill them, the same as we had before. However, now the state is stored in the Board component instead of the individual Square components. When the Board's state changes, the Square components re-render automatically. Keeping the state of all squares in the Board component will allow it to determine the winner in the future.
543519

544520
Since the Square components no longer maintain state, the Square components receive values from the Board component and inform the Board component when they're clicked. In React terms, the Square components are now **controlled components**. The Board has full control over them.
545521

@@ -581,7 +557,7 @@ Detecting changes in mutable objects is difficult because they are modified dire
581557

582558
Detecting changes in immutable objects is considerably easier. If the immutable object that is being referenced is different than the previous one, then the object has changed.
583559

584-
#### Determining When to Re-render in React {#determining-when-to-re-render-in-react}
560+
#### Determining When to Re-Render in React {#determining-when-to-re-render-in-react}
585561

586562
The main benefit of immutability is that it helps you build _pure components_ in React. Immutable data can easily determine if changes have been made which helps to determine when a component requires re-rendering.
587563

@@ -611,7 +587,7 @@ Nos modificamos `this.props` para `props` nas duas vezes que ela aparece.
611587

612588
>Nota
613589
>
614-
>Quando modificamos Square para ser um componente funcional, também modificamos `onClick={() => this.props.onClick()}` para uma versão mais curta: `onClick={props.onClick}` (note a ausência dos parenteses em *ambos* os lados). Em uma classe, nós utilizamos uma arrow function para acessar o valor correto de `this`, mas para um componente funcional não precisamos nos preocupar com `this`.
590+
>Quando modificamos Square para ser um componente funcional, também modificamos `onClick={() => this.props.onClick()}` para uma versão mais curta: `onClick={props.onClick}` (note a ausência dos parenteses em *ambos* os lados).
615591
616592
### Trocando Turnos {#taking-turns}
617593

@@ -643,7 +619,9 @@ Sempre que um jogador fizer uma jogada, `xIsNext` (um boolean) será trocado par
643619
}
644620
```
645621

646-
Com esse mudança,"X"s e "O"s podem trocar os turnos. Também vamos modificar o texto de "status" na função `render` do Board para que ela passe a exibir quem jogará o próximo turno.
622+
Com esse mudança,"X"s e "O"s podem trocar os turnos. Tente!
623+
624+
Também vamos modificar o texto de "status" na função `render` do Board para que ela passe a exibir quem jogará o próximo turno.
647625

648626
```javascript{2}
649627
render() {
@@ -714,7 +692,7 @@ class Board extends React.Component {
714692

715693
### Declarando um Vencedor {#declaring-a-winner}
716694

717-
Agora que mostramos quem jogará o próximo turno, também deveríamos mostrar quando o jogo foi vencido e que não há mais turnos a serem jogados. Podemos determinar um vencedor adicionando essa função auxiliar ao final do arquivo:
695+
Agora que mostramos quem jogará o próximo turno, também deveríamos mostrar quando o jogo foi vencido e que não há mais turnos a serem jogados. Copie essa função auxiliar e cole-a no final do arquivo:
718696

719697
```javascript
720698
function calculateWinner(squares) {
@@ -738,6 +716,8 @@ function calculateWinner(squares) {
738716
}
739717
```
740718

719+
Dado um array de 9 quadrados, esta função irá verificar se há um vencedor e retornará `'X'`, `'O'` ou `null` conforme apropriado
720+
741721
Chamaremos `calculateWinner(squares)` na função `render` do Board para checar se um jogador venceu. Caso tenha vencido, podemos mostrar um texto como "Winner: X" ou "Winner: O". Vamos substituir a declaração de `status` na função `render` com esse código:
742722

743723
```javascript{2-8}
@@ -777,6 +757,7 @@ Parabéns! Você agora tem um Jogo da Velha funcionando! E também acaba de apre
777757
## Adicionando a Viagem no Tempo (Time Travel){#adding-time-travel}
778758

779759
Como um último exercício, vamos tornar possível fazer uma "volta no tempo" até as jogadas anteriores que aconteceram no jogo.
760+
780761
### Armazenando um Histórico de Jogadas {#storing-a-history-of-moves}
781762

782763
Se nós tivéssemos modificado o array `squares`, a implementação da volta no tempo seria muito difícil.

0 commit comments

Comments
 (0)