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
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.
244
244
245
245
```js
246
246
setNumber(0+5);
@@ -249,16 +249,16 @@ setTimeout(() => {
249
249
}, 3000);
250
250
```
251
251
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!
253
253
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.
255
255
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:
257
257
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".
260
260
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ź:
262
262
263
263
<Sandpack>
264
264
@@ -267,19 +267,19 @@ import { useState } from 'react';
267
267
268
268
exportdefaultfunctionForm() {
269
269
const [to, setTo] =useState('Alice');
270
-
const [message, setMessage] =useState('Hello');
270
+
const [message, setMessage] =useState('Cześć');
271
271
272
272
functionhandleSubmit(e) {
273
273
e.preventDefault();
274
274
setTimeout(() => {
275
-
alert(`You said ${message}to${to}`);
275
+
alert(`Powiedziałeś/aś ${message}do${to}`);
276
276
}, 5000);
277
277
}
278
278
279
279
return (
280
280
<form onSubmit={handleSubmit}>
281
281
<label>
282
-
To:{''}
282
+
Do:{''}
283
283
<select
284
284
value={to}
285
285
onChange={e=>setTo(e.target.value)}>
@@ -288,11 +288,11 @@ export default function Form() {
**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.
308
308
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!
310
310
311
311
<Recap>
312
312
@@ -432,3 +432,6 @@ So clicking "Change to Stop" queues a render with `walk` set to `false`, and ale
0 commit comments