Skip to content

Commit b7aa9b0

Browse files
committed
rendering-takes-a-snapshot-in-time
1 parent db1b041 commit b7aa9b0

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,35 +69,35 @@ Oto co dzieje się, gdy klikniesz przycisk:
6969

7070
Przyjrzyjmy się bliżej związkowi między stanem a renderowaniem.
7171

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*/}
7373

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.**
7575

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.
7777

78-
When React re-renders a component:
78+
Kiedy React ponownie renderuje komponent:
7979

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ę.
8383

8484
<IllustrationBlock sequential>
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+
<Illustration caption="React wykonuje funkcję" src="/images/docs/illustrations/i_render1.png" />
86+
<Illustration caption="Oblicza migawkę" src="/images/docs/illustrations/i_render2.png" />
87+
<Illustration caption="Aktualizuje drzewo DOM" src="/images/docs/illustrations/i_render3.png" />
8888
</IllustrationBlock>
8989

90-
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!**
9191

9292
<IllustrationBlock sequential>
93-
<Illustration caption="You tell React to update the state" src="/images/docs/illustrations/i_state-snapshot1.png" />
94-
<Illustration caption="React updates the state value" src="/images/docs/illustrations/i_state-snapshot2.png" />
95-
<Illustration caption="React passes a snapshot of the state value into the component" src="/images/docs/illustrations/i_state-snapshot3.png" />
93+
<Illustration caption="Informujesz Reacta o konieczności aktualizacji stanu" src="/images/docs/illustrations/i_state-snapshot1.png" />
94+
<Illustration caption="React aktualizuje wartość stanu" src="/images/docs/illustrations/i_state-snapshot2.png" />
95+
<Illustration caption="React przekazuje migawkę wartości stanu do komponentu" src="/images/docs/illustrations/i_state-snapshot3.png" />
9696
</IllustrationBlock>
9797

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.
9999

100-
See what happens when you click the "+3" button:
100+
Zobacz, co się stanie po kliknięciu przycisku "+3":
101101

102102
<Sandpack>
103103

@@ -127,9 +127,9 @@ h1 { display: inline-block; margin: 10px; width: 30px; text-align: center; }
127127

128128
</Sandpack>
129129

130-
Notice that `number` only increments once per click!
130+
Zauważ, że `number` zwiększa się tylko o jeden za każdym kliknięciem!
131131

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)`:
133133

134134
```js
135135
<button onClick={() => {
@@ -139,18 +139,18 @@ Notice that `number` only increments once per click!
139139
}}>+3</button>
140140
```
141141

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:
143143

144-
1. `setNumber(number + 1)`: `number` is `0` so `setNumber(0 + 1)`.
145-
- React prepares to change `number` to `1` on the next render.
146-
2. `setNumber(number + 1)`: `number` is `0` so `setNumber(0 + 1)`.
147-
- React prepares to change `number` to `1` on the next render.
148-
3. `setNumber(number + 1)`: `number` is `0` so `setNumber(0 + 1)`.
149-
- 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.
150150

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`.
152152

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:
154154

155155
```js
156156
<button onClick={() => {
@@ -159,8 +159,7 @@ You can also visualize this by mentally substituting state variables with their
159159
setNumber(0 + 1);
160160
}}>+3</button>
161161
```
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:
164163

165164
```js
166165
<button onClick={() => {
@@ -170,7 +169,7 @@ For the next render, `number` is `1`, so *that render's* click handler looks lik
170169
}}>+3</button>
171170
```
172171

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.
174173

175174
## State over time {/*state-over-time*/}
176175

0 commit comments

Comments
 (0)