Skip to content

Commit 55d1f96

Browse files
committed
implement-a-traffic-light*
1 parent 1a948f3 commit 55d1f96

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/content/learn/state-as-a-snapshot.md

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,9 @@ A co, jeśli chcesz odczytać najnowszy stan przed ponownym renderowaniem? Wtedy
324324

325325
<Challenges>
326326

327-
#### Implement a traffic light {/*implement-a-traffic-light*/}
327+
#### Zaimplementuj światła uliczne {/*implement-a-traffic-light*/}
328328

329-
Here is a crosswalk light component that toggles when the button is pressed:
329+
Oto komponent świateł na przejściu dla pieszych, który przełącza się po naciśnięciu przycisku:
330330

331331
<Sandpack>
332332

@@ -343,12 +343,12 @@ export default function TrafficLight() {
343343
return (
344344
<>
345345
<button onClick={handleClick}>
346-
Change to {walk ? 'Stop' : 'Walk'}
346+
Zmień na {walk ? 'Stój' : 'Idź'}
347347
</button>
348348
<h1 style={{
349349
color: walk ? 'darkgreen' : 'darkred'
350350
}}>
351-
{walk ? 'Walk' : 'Stop'}
351+
{walk ? 'Idź' : 'Stój'}
352352
</h1>
353353
</>
354354
);
@@ -361,13 +361,13 @@ h1 { margin-top: 20px; }
361361

362362
</Sandpack>
363363

364-
Add an `alert` to the click handler. When the light is green and says "Walk", clicking the button should say "Stop is next". When the light is red and says "Stop", clicking the button should say "Walk is next".
364+
Dodaj `alert` do procedury obsługi kliknięcia. Kiedy światło jest zielone i wyświetla "Idź", kliknięcie przycisku powinno pokazać "Następnie będzie Stój". Kiedy światło jest czerwone i wyświetla "Stój", kliknięcie przycisku powinno pokazać "Następnie będzie Idź".
365365

366-
Does it make a difference whether you put the `alert` before or after the `setWalk` call?
366+
Czy ma znaczenie, czy umieścisz `alert` przed czy po wywołaniu `setWalk`?
367367

368368
<Solution>
369369

370-
Your `alert` should look like this:
370+
Twój `alert` powinien wyglądać tak:
371371

372372
<Sandpack>
373373

@@ -379,18 +379,18 @@ export default function TrafficLight() {
379379

380380
function handleClick() {
381381
setWalk(!walk);
382-
alert(walk ? 'Stop is next' : 'Walk is next');
382+
alert(walk ? 'Następnie będzie Stój' : 'Następnie będzie Idź');
383383
}
384384

385385
return (
386386
<>
387387
<button onClick={handleClick}>
388-
Change to {walk ? 'Stop' : 'Walk'}
388+
Zmień na {walk ? 'Stój' : 'Idź'}
389389
</button>
390390
<h1 style={{
391391
color: walk ? 'darkgreen' : 'darkred'
392392
}}>
393-
{walk ? 'Walk' : 'Stop'}
393+
{walk ? 'Idź' : 'Stój'}
394394
</h1>
395395
</>
396396
);
@@ -403,31 +403,31 @@ h1 { margin-top: 20px; }
403403

404404
</Sandpack>
405405

406-
Whether you put it before or after the `setWalk` call makes no difference. That render's value of `walk` is fixed. Calling `setWalk` will only change it for the *next* render, but will not affect the event handler from the previous render.
406+
Nie ma znaczenia, czy umieścisz alert przed czy po wywołaniu `setWalk`. Wartość `walk` dla tego renderowania jest ustalona. Wywołanie `setWalk` zmieni ją tylko dla *następnego* renderowania, ale nie wpłynie na procedurę obsługi zdarzeń z poprzedniego renderowania.
407407

408-
This line might seem counter-intuitive at first:
408+
Ta linia może początkowo wydawać się nieintuicyjna:
409409

410410
```js
411-
alert(walk ? 'Stop is next' : 'Walk is next');
411+
alert(walk ? 'Następnie będzie Stój' : 'Następnie będzie Idź');
412412
```
413413

414-
But it makes sense if you read it as: "If the traffic light shows 'Walk now', the message should say 'Stop is next.'" The `walk` variable inside your event handler matches that render's value of `walk` and does not change.
414+
Ale ma ona sens, jeśli przeczytasz ją tak: "Jeśli sygnalizator pokazuje 'Idź', komunikat powinien brzmieć 'Następnie będzie Stój'". Zmienna `walk` wewnątrz procedury obsługi zdarzeń odpowiada wartości `walk` z tego renderowania i nie zmienia się.
415415

416-
You can verify that this is correct by applying the substitution method. When `walk` is `true`, you get:
416+
Możesz to zweryfikować, stosując metodę podstawiania. Kiedy `walk` ma wartość `true`, otrzymujesz:
417417

418418
```js
419419
<button onClick={() => {
420420
setWalk(false);
421-
alert('Stop is next');
421+
alert('Następnie będzie Stój');
422422
}}>
423-
Change to Stop
423+
Zmień na Stój
424424
</button>
425425
<h1 style={{color: 'darkgreen'}}>
426-
Walk
426+
Idź
427427
</h1>
428428
```
429429

430-
So clicking "Change to Stop" queues a render with `walk` set to `false`, and alerts "Stop is next".
430+
Więc kliknięcie "Zmień na Stój" dodaje do kolejki renderowanie z `walk` ustawionym na `false` i wyświetla alert "Następnie będzie Stój".
431431

432432
</Solution>
433433

0 commit comments

Comments
 (0)