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: src/content/learn/tutorial-tic-tac-toe.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1749,11 +1749,11 @@ Tallennat aikaisemmat `squares` taulukot toiseen taulukoon nimeltään `history`
1749
1749
1750
1750
### Tilan nostaminen ylös, uudestaan {/*lifting-state-up-again*/}
1751
1751
1752
-
You will now write a new top-level component called `Game`to display a list of past moves. That's where you will place the `history`state that contains the entire game history.
1752
+
Tulet kirjoittamaan uuden ylätason komponentin nimeltään `Game`näyttämään listan aiemmista liikkeistä. Tähän tulee `history`tila, joka sisältää koko pelin historian.
1753
1753
1754
-
Placing the `history`state into the `Game`component will let you remove the `squares`state from its child `Board`component. Just like you "lifted state up" from the `Square`component into the `Board`component, you will now lift it up from the `Board`into the top-level `Game`component. This gives the `Game`component full control over the `Board`'s data and lets it instruct the`Board`to render previous turns from the `history`.
1754
+
`history`tilan asettaminen `Game`komponenttiin antaa sinun poistaa `squares`tilan sen `Board`alakomponentista. Aivan kuten "nostit tilan ylös" `Square`komponentista `Board`komponenttiin, nostat sen nyt `Board`komponentista ylätason `Game`komponenttiin. Tämä antaa `Game`komponentille täyden kontrollin `Board`:n datan yli ja antaa sen ohjata`Board`komponenttia renderöimään edelliset vuorot `history`:sta.
1755
1755
1756
-
First, add a `Game`component with `exportdefault`. Have it render the `Board`component and some markup:
1756
+
Ensiksi, lisää `Game`komponentti `exportdefault`:lla. Aseta se renderöimään `Board`komponentti ja joitain merkintäkoodia:
1757
1757
1758
1758
```js {1,5-16}
1759
1759
functionBoard() {
@@ -1774,9 +1774,9 @@ export default function Game() {
1774
1774
}
1775
1775
```
1776
1776
1777
-
Note that you are removing the `exportdefault`keywords before the `functionBoard() {`declaration and adding them before the `functionGame() {`declaration. This tells your `index.js`file to use the `Game`component as the top-level component instead of your `Board`component. The additional `div`s returned by the `Game`component are making room for the game information you'll add to the board later.
1777
+
Huomaa, että olet poistamassa `exportdefault`avainsanat ennen `functionBoard() {`määrittelyä ja lisäämässä ne ennen `functionGame() {`määrittelyä. Tämä kertoo `index.js`tiedostolle käyttää `Game`komponenttia ylätason komponenttina sen sijaan, että käyttäisit `Board`komponenttia. Lisä `div`:t, jotka `Game`komponentti palauttaa, tekevät tilaa pelin tiedoille, jotka lisäät pelilaudalle myöhemmin.
1778
1778
1779
-
Add some state to the `Game`component to track which player is next and the history of moves:
1779
+
Lisää tila `Game`komponenttiin seuraamaan kumpi pelaaja on seuraavaksi ja pelin siirtojen historia:
1780
1780
1781
1781
```js {2-3}
1782
1782
exportdefaultfunctionGame() {
@@ -1785,9 +1785,9 @@ export default function Game() {
1785
1785
// ...
1786
1786
```
1787
1787
1788
-
Notice how`[Array(9).fill(null)]`is an array with a single item, which itself is an array of 9 `null`s.
1788
+
Huomaa miten`[Array(9).fill(null)]`on taulukko, jossa on yksi alkio, joka on taulukko, jossa on 9 `null`:a.
1789
1789
1790
-
To render the squares for the current move, you'll want to read the last squares array from the `history`. You don't need `useState` for this--you already have enough information to calculate it during rendering:
1790
+
Renderöidäksesi neliöt nykyiselle siirrolle, luet viimeisen `squares` taulukon `history`:sta. Et tarvitse `useState`:a tähän--sinulla on jo tarpeeksi tietoa laskeaksesi se renderöinnin aikana:
1791
1791
1792
1792
```js {4}
1793
1793
exportdefaultfunctionGame() {
@@ -1797,7 +1797,7 @@ export default function Game() {
1797
1797
// ...
1798
1798
```
1799
1799
1800
-
Next, create a `handlePlay`function inside the `Game`component that will be called by the `Board`component to update the game. Pass`xIsNext`, `currentSquares`and`handlePlay`as props to the `Board`component:
1800
+
Seuraavaksi, luo `handlePlay`funktio `Game`komponenttiin, jota kutsutaan `Board`komponentin toimesta päivittämään peliä. Välitä`xIsNext`, `currentSquares`ja`handlePlay`propseina `Board`komponentille:
1801
1801
1802
1802
```js {6-8,13}
1803
1803
exportdefaultfunctionGame() {
@@ -1818,7 +1818,7 @@ export default function Game() {
1818
1818
}
1819
1819
```
1820
1820
1821
-
Let's make the `Board`component fully controlled by the props it receives. Change the `Board`component to take three props: `xIsNext`, `squares`, and a new `onPlay`function that`Board`can call with the updated squares array when a player makes a move. Next, remove the first two lines of the `Board`function that call`useState`:
1821
+
Tehdään `Board`komponentista täysin propseilla kontrolloitava. Muuta `Board`komponentti ottamaan kolme propia: `xIsNext`, `squares`, ja uusi `onPlay`funktio, jota`Board`voi kutsua päivitetyn taulukon kanssa, kun pelaaja tekee siirron. Poista seuraavaksi kaksi ensimmäistä riviä `Board`funktiosta, jotka kutsuvat`useState`:a:
Now replace the `setSquares`and`setXIsNext`calls in `handleClick` in the `Board`component with a single call to your new `onPlay`function so the `Game`component can update the `Board` when the user clicks a square:
1832
+
Nyt korvaa `setSquares`ja`setXIsNext`kutsut `handleClick`:ssa `Board`komponentissa yhdellä kutsulla uuteen `onPlay`funktioon, jotta `Game`komponentti voi päivittää `Board`:n, kun käyttäjä klikkaa neliötä:
The `Board`component is fully controlled by the props passed to it by the `Game`component. You need to implement the `handlePlay`function in the `Game`component to get the game working again.
1852
+
`Board`komponentti on täysin kontrolloitu propseilla, jotka sille välitetään `Game`komponentista. Sinun täytyy toteuttaa `handlePlay`funktio `Game`komponenttiin saadaksesi pelin toimimaan uudestaan.
1853
1853
1854
-
What should `handlePlay` do when called? Remember that Board used to call `setSquares` with an updated array; now it passes the updated `squares`array to `onPlay`.
1854
+
Mitä `handlePlay`:n tulisi tehdä kun sitä kutsutaan? Muista, että `Board` kutsui `setSquares`:ia päivitetyllä taulukolla. Nyt se välittää päivitetyn `squares`taulukon `onPlay`:lle.
1855
1855
1856
-
The `handlePlay`function needs to update `Game`'s state to trigger a re-render, but you don't have a`setSquares`function that you can call any more--you're now using the `history`state variable to store this information. You'll want to update `history` by appending the updated `squares`array as a new history entry. You also want to toggle `xIsNext`, just as Board used to do:
1856
+
`handlePlay`funktion täytyy päivittää `Game`:n tila käynnistääkseen renderöinnin, mutta sinulla ei ole enää`setSquares`funktiota, jota voit kutsua--käytät nyt `history`tilamuuttujaa tallentaaksesi tämän tiedon. Haluat päivittää `history`:n lisäämällä päivitetyn `squares`taulukon uutena historiaan. Haluat myös kääntää `xIsNext`:n, aivan kuten `Board` teki ennen:
1857
1857
1858
1858
```js {4-5}
1859
1859
exportdefaultfunctionGame() {
@@ -1866,11 +1866,11 @@ export default function Game() {
1866
1866
}
1867
1867
```
1868
1868
1869
-
Here, `[...history, nextSquares]`creates a new array that contains all the items in `history`, followed by `nextSquares`. (You can read the `...history` [*spread syntax*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) as "enumerate all the items in `history`".)
1869
+
Tässä, `[...history, nextSquares]`luo uuden taulukon, joka sisältää kaikki `history`:n alkiot, seurattuna `nextSquares`:lla. (Voit lukea `...history` [*spread syntaksin*](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_syntax) "luettele kaikki `history` taulukon alkiot".)
1870
1870
1871
-
For example, if`history`is`[[null,null,null], ["X",null,null]]`and`nextSquares`is`["X",null,"O"]`, then the new `[...history, nextSquares]`array will be `[[null,null,null], ["X",null,null], ["X",null,"O"]]`.
1871
+
Esimerkiksi, jos`history`on`[[null,null,null], ["X",null,null]]`ja`nextSquares`on`["X",null,"0"]`, niin uusi `[...history, nextSquares]`taulukko on `[[null,null,null], ["X",null,null], ["X",null,"0"]]`.
1872
1872
1873
-
At this point, you've moved the state to live in the `Game`component, and the UI should be fully working, just as it was before the refactor. Here is what the code should look like at this point:
1873
+
Tässä kohtaa, olet siirtänyt tilan `Game`komponenttiin, ja käyttöliittymä tulisi toimia täysin, aivan kuten ennen refaktorointia. Tässä on miltä koodisi tulisi näyttää tässä vaiheessa:
0 commit comments