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/state-as-a-snapshot.md
+29-30Lines changed: 29 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -69,35 +69,35 @@ Oto co dzieje się, gdy klikniesz przycisk:
69
69
70
70
Przyjrzyjmy się bliżej związkowi między stanem a renderowaniem.
71
71
72
-
## Rendering takes a snapshot in time {/*rendering-takes-a-snapshot-in-time*/}
72
+
## Renderowanie tworzy migawkę danego momentu {/*rendering-takes-a-snapshot-in-time*/}
73
73
74
-
["Rendering"](/learn/render-and-commit#step-2-react-renders-your-components)means that React is calling your component, which is a function. The JSX you return from that function is like a snapshot of the UI in time. Its props, event handlers, and local variables were all calculated**using its state at the time of the render.**
74
+
["Renderowanie"](/learn/render-and-commit#step-2-react-renders-your-components)oznacza, że React wywołuje twój komponent, który jest funkcją. Zwracany przez tę funkcję JSX jest jak migawka interfejsu użytkownika w danym momencie. Jego właściwości, procedury obsługi zdarzeń i zmienne lokalne zostały obliczone**na podstawie stanu w momencie renderowania.**
75
75
76
-
Unlike a photograph or a movie frame, the UI "snapshot" you return is interactive. It includes logic like event handlers that specify what happens in response to inputs. React updates the screen to match this snapshot and connects the event handlers. As a result, pressing a button will trigger the click handler from your JSX.
76
+
W przeciwieństwie do fotografii czy klatki filmu, "migawka" interfejsu użytkownika, którą zwracasz jest interaktywna. Zawiera logikę, taką jak procedury obsługi zdarzeń, które określają co się stanie w odpowiedzi na dane wejściowe. React aktualizuje ekran, aby dopasować go do tej migawki i podłącza procedury obsługi zdarzeń. W rezultacie naciśnięcie przycisku uruchomi procedurę obsługi kliknięcia z twojego JSX.
77
77
78
-
When React re-renders a component:
78
+
Kiedy React ponownie renderuje komponent:
79
79
80
-
1. React calls your function again.
81
-
2.Your function returns a new JSX snapshot.
82
-
3. React then updates the screen to match the snapshot your function returned.
80
+
1. React ponownie wywołuje twoją funkcję.
81
+
2.Twoja funkcja zwraca nową migawkę JSX.
82
+
3. React następnie aktualizuje ekran, aby dopasować go do migawki zwróconej przez twoją funkcję.
83
83
84
84
<IllustrationBlocksequential>
85
-
<Illustration caption="React executing the function" src="/images/docs/illustrations/i_render1.png" />
86
-
<Illustration caption="Calculating the snapshot" src="/images/docs/illustrations/i_render2.png" />
87
-
<Illustration caption="Updating the DOM tree" src="/images/docs/illustrations/i_render3.png" />
85
+
<Illustrationcaption="React wykonuje funkcję"src="/images/docs/illustrations/i_render1.png" />
As a component's memory, state is not like a regular variable that disappears after your function returns. State actually "lives" in React itself--as if on a shelf!--outside of your function. When React calls your component, it gives you a snapshot of the state for that particular render. Your component returns a snapshot of the UI with a fresh set of props and event handlers in its JSX, all calculated **using the state values from that render!**
90
+
Jako pamięć komponentu, stan nie jest jak zwykła zmienna, która znika po zakończeniu działania funkcji. Stan naprawdę "żyje" w samym Reakcie (jakby był na półce!) poza twoją funkcją. Kiedy React wywołuje twój komponent, przekazuje ci migawkę stanu dla tego konkretnego renderowania. Twój komponent zwraca migawkę interfejsu użytkownika ze świeżym zestawem właściwości i procedur obsługi zdarzeń w swoim JSX, gdzie wszystko jest obliczone **przy użyciu wartości stanu z tego renderowania!**
91
91
92
92
<IllustrationBlocksequential>
93
-
<Illustrationcaption="You tell React to update the state"src="/images/docs/illustrations/i_state-snapshot1.png" />
94
-
<Illustrationcaption="React updates the state value"src="/images/docs/illustrations/i_state-snapshot2.png" />
95
-
<Illustrationcaption="React passes a snapshot of the state value into the component"src="/images/docs/illustrations/i_state-snapshot3.png" />
93
+
<Illustrationcaption="Informujesz Reacta o konieczności aktualizacji stanu"src="/images/docs/illustrations/i_state-snapshot1.png" />
94
+
<Illustrationcaption="React aktualizuje wartość stanu"src="/images/docs/illustrations/i_state-snapshot2.png" />
95
+
<Illustrationcaption="React przekazuje migawkę wartości stanu do komponentu"src="/images/docs/illustrations/i_state-snapshot3.png" />
96
96
</IllustrationBlock>
97
97
98
-
Here's a little experiment to show you how this works. In this example, you might expect that clicking the "+3" button would increment the counter three times because it calls `setNumber(number + 1)`three times.
98
+
Oto mały eksperyment pokazujący, jak to działa. W tym przykładzie można by się spodziewać, że kliknięcie przycisku "+3" zwiększy licznik trzykrotnie, ponieważ wywołuje on `setNumber(number + 1)`trzy razy.
99
99
100
-
See what happens when you click the "+3" button:
100
+
Zobacz, co się stanie po kliknięciu przycisku "+3":
Notice that`number`only increments once per click!
130
+
Zauważ, że`number`zwiększa się tylko o jeden za każdym kliknięciem!
131
131
132
-
**Setting state only changes it for the *next* render.**During the first render, `number`was `0`. This is why, in *that render's*`onClick`handler, the value of`number`is still`0` even after `setNumber(number + 1)` was called:
132
+
**Ustawienie stanu zmienia go dopiero w *następnym* renderowaniu.**Podczas pierwszego renderowania `number`miał wartość `0`. Dlatego w procedurze obsługi `onClick`dla *tego renderowania* wartość`number`nadal wynosi`0`, nawet po wywołaniu `setNumber(number + 1)`:
133
133
134
134
```js
135
135
<button onClick={() => {
@@ -139,18 +139,18 @@ Notice that `number` only increments once per click!
139
139
}}>+3</button>
140
140
```
141
141
142
-
Here is what this button's click handler tells React to do:
142
+
Oto co procedura obsługi kliknięcia tego przycisku każe zrobić Reactowi:
- React prepares to change `number`to`1`on the next render.
144
+
1.`setNumber(number + 1)`: `number`wynosi`0`, więc to inaczej`setNumber(0 + 1)`.
145
+
- React przygotowuje się do zmiany `number`na`1`przy następnym renderowaniu.
146
+
2.`setNumber(number + 1)`: `number`wynosi`0`, więc to inaczej`setNumber(0 + 1)`.
147
+
- React przygotowuje się do zmiany `number`na`1`przy następnym renderowaniu.
148
+
3.`setNumber(number + 1)`: `number`wynosi`0`, więc to inaczej`setNumber(0 + 1)`.
149
+
- React przygotowuje się do zmiany `number`na`1`przy następnym renderowaniu.
150
150
151
-
Even though you called `setNumber(number + 1)`three times, in *this render's* event handler `number`is always`0`, so you set the state to`1` three times. This is why, after your event handler finishes, React re-renders the component with`number`equal to `1` rather than`3`.
151
+
Mimo że wywołano `setNumber(number + 1)`trzy razy, w procedurze obsługi zdarzeń *tego renderowania*`number`zawsze wynosi`0`, więc trzy razy ustawiono stan na`1`. Dlatego po zakończeniu działania procedury obsługi zdarzeń, React ponownie renderuje komponent z`number`równym `1`, a nie`3`.
152
152
153
-
You can also visualize this by mentally substituting state variables with their values in your code. Since the `number`state variable is `0`for *this render*, its event handler looks like this:
153
+
Możesz to sobie również zwizualizować, podstawiając w myślach wartości zmiennych stanu w swoim kodzie. Ponieważ zmienna stanu `number`ma wartość `0`dla *tego renderowania*, jego procedura obsługi zdarzeń wygląda tak:
154
154
155
155
```js
156
156
<button onClick={() => {
@@ -159,8 +159,7 @@ You can also visualize this by mentally substituting state variables with their
159
159
setNumber(0+1);
160
160
}}>+3</button>
161
161
```
162
-
163
-
For the next render, `number` is `1`, so *that render's* click handler looks like this:
162
+
Dla następnego renderowania `number` wynosi `1`, więc procedura obsługi kliknięcia *tego renderowania* wygląda tak:
164
163
165
164
```js
166
165
<button onClick={() => {
@@ -170,7 +169,7 @@ For the next render, `number` is `1`, so *that render's* click handler looks lik
170
169
}}>+3</button>
171
170
```
172
171
173
-
This is why clicking the button again will set the counter to `2`, then to`3`on the next click, and so on.
172
+
Dlatego ponowne kliknięcie przycisku ustawi licznik na `2`, następnie na`3`przy kolejnym kliknięciu i tak dalej.
0 commit comments