Skip to content

Commit b278978

Browse files
committed
state-over-time
1 parent b7aa9b0 commit b278978

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

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

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ Dla następnego renderowania `number` wynosi `1`, więc procedura obsługi klikn
171171

172172
Dlatego ponowne kliknięcie przycisku ustawi licznik na `2`, następnie na `3` przy kolejnym kliknięciu i tak dalej.
173173

174-
## State over time {/*state-over-time*/}
174+
## Stan w czasie {/*state-over-time*/}
175175

176-
Well, that was fun. Try to guess what clicking this button will alert:
176+
To było ciekawe. Spróbuj teraz zgadnąć, co wyświetli alert po kliknięciu tego przycisku:
177177

178178
<Sandpack>
179179

@@ -202,14 +202,14 @@ h1 { display: inline-block; margin: 10px; width: 30px; text-align: center; }
202202

203203
</Sandpack>
204204

205-
If you use the substitution method from before, you can guess that the alert shows "0":
205+
Jeśli zastosujesz metodę podstawiania wspomnianą wcześniej, możesz zgadnąć, że alert pokaże "0":
206206

207207
```js
208208
setNumber(0 + 5);
209209
alert(0);
210210
```
211211

212-
But what if you put a timer on the alert, so it only fires _after_ the component re-rendered? Would it say "0" or "5"? Have a guess!
212+
A co, jeśli dodasz timer do alertu, tak aby wyświetlił się dopiero _po_ ponownym wyrenderowaniu komponentu? Czy pokaże on "0" czy "5"? Zgadnij!
213213

214214
<Sandpack>
215215

@@ -240,7 +240,7 @@ h1 { display: inline-block; margin: 10px; width: 30px; text-align: center; }
240240

241241
</Sandpack>
242242

243-
Surprised? If you use the substitution method, you can see the "snapshot" of the state passed to the alert.
243+
Zaskoczenie? Jeśli zastosujesz metodę podstawiania, zobaczysz "migawkę" stanu przekazaną do alertu.
244244

245245
```js
246246
setNumber(0 + 5);
@@ -249,16 +249,16 @@ setTimeout(() => {
249249
}, 3000);
250250
```
251251

252-
The state stored in React may have changed by the time the alert runs, but it was scheduled using a snapshot of the state at the time the user interacted with it!
252+
Stan przechowywany w Reakcie może się zmienić do czasu wyświetlenia alertu, ale alert ten został zaplanowany przy użyciu migawki stanu z momentu interakcji użytkownika!
253253

254-
**A state variable's value never changes within a render,** even if its event handler's code is asynchronous. Inside *that render's* `onClick`, the value of `number` continues to be `0` even after `setNumber(number + 5)` was called. Its value was "fixed" when React "took the snapshot" of the UI by calling your component.
254+
**Wartość zmiennej stanu nigdy nie zmienia się w obrębie pojedynczego renderowania,** nawet jeśli kod jej procedury obsługi zdarzeń jest asynchroniczny. Wewnątrz metody `onClick` *tego renderowania*, wartość zmiennej `number` nadal wynosi `0`, nawet po wywołaniu `setNumber(number + 5)`. Jej wartość została "utrwalona" w momencie, gdy React "zrobił migawkę" interfejsu użytkownika poprzez wywołanie twojego komponentu.
255255

256-
Here is an example of how that makes your event handlers less prone to timing mistakes. Below is a form that sends a message with a five-second delay. Imagine this scenario:
256+
Oto przykład pokazujący, jak to sprawia, że procedury obsługi zdarzeń są mniej podatne na błędy związane z czasem wykonania. Poniżej znajduje się formularz, który wysyła wiadomość z pięciosekundowym opóźnieniem. Wyobraź sobie taki scenariusz:
257257

258-
1. You press the "Send" button, sending "Hello" to Alice.
259-
2. Before the five-second delay ends, you change the value of the "To" field to "Bob".
258+
1. Naciskasz przycisk "Wyślij", aby wysłać wiadomość "Cześć" do Alice.
259+
2. Zanim upłynie pięciosekundowe opóźnienie, zmieniasz wartość pola "Do" na "Bob".
260260

261-
What do you expect the `alert` to display? Would it display, "You said Hello to Alice"? Or would it display, "You said Hello to Bob"? Make a guess based on what you know, and then try it:
261+
Jak myślisz, co wyświetli `alert`? Czy pokaże "Powiedziałeś/aś Cześć do Alice"? A może "Powiedziałeś/aś Cześć do Boba"? Spróbuj zgadnąć na podstawie tego, czego udało się ci dowiedzieć, a następnie sprawdź:
262262

263263
<Sandpack>
264264

@@ -267,19 +267,19 @@ import { useState } from 'react';
267267

268268
export default function Form() {
269269
const [to, setTo] = useState('Alice');
270-
const [message, setMessage] = useState('Hello');
270+
const [message, setMessage] = useState('Cześć');
271271

272272
function handleSubmit(e) {
273273
e.preventDefault();
274274
setTimeout(() => {
275-
alert(`You said ${message} to ${to}`);
275+
alert(`Powiedziałeś/aś ${message} do ${to}`);
276276
}, 5000);
277277
}
278278

279279
return (
280280
<form onSubmit={handleSubmit}>
281281
<label>
282-
To:{' '}
282+
Do:{' '}
283283
<select
284284
value={to}
285285
onChange={e => setTo(e.target.value)}>
@@ -288,11 +288,11 @@ export default function Form() {
288288
</select>
289289
</label>
290290
<textarea
291-
placeholder="Message"
291+
placeholder="Wiadomość"
292292
value={message}
293293
onChange={e => setMessage(e.target.value)}
294294
/>
295-
<button type="submit">Send</button>
295+
<button type="submit">Wyślij</button>
296296
</form>
297297
);
298298
}
@@ -304,9 +304,9 @@ label, textarea { margin-bottom: 10px; display: block; }
304304

305305
</Sandpack>
306306

307-
**React keeps the state values "fixed" within one render's event handlers.** You don't need to worry whether the state has changed while the code is running.
307+
**React zachowuje wartości stanu jako "utrwalone" w procedurach obsługi zdarzeń dla danego renderowania.** Nie musisz się martwić, czy stan zmienił się podczas wykonywania kodu.
308308

309-
But what if you wanted to read the latest state before a re-render? You'll want to use a [state updater function](/learn/queueing-a-series-of-state-updates), covered on the next page!
309+
A co, jeśli chcesz odczytać najnowszy stan przed ponownym renderowaniem? Będziesz potrzebować [funkcji aktualizującej stan](/learn/queueing-a-series-of-state-updates), którą omówimy na następnej stronie!
310310

311311
<Recap>
312312

@@ -432,3 +432,6 @@ So clicking "Change to Stop" queues a render with `walk` set to `false`, and ale
432432
</Solution>
433433

434434
</Challenges>
435+
436+
437+
[def]: /learn/queueing-a-series-of-state-updates

0 commit comments

Comments
 (0)