Skip to content

Commit efe1110

Browse files
committed
Translate 'FAQ: Component State' page
1 parent b24410c commit efe1110

File tree

1 file changed

+43
-43
lines changed

1 file changed

+43
-43
lines changed

content/docs/faq-state.md

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,106 @@
11
---
22
id: faq-state
3-
title: Component State
3+
title: Stan komponentu
44
permalink: docs/faq-state.html
55
layout: docs
66
category: FAQ
77
---
88

9-
### What does `setState` do? {#what-does-setstate-do}
9+
### Co robi `setState`? {#what-does-setstate-do}
1010

11-
`setState()` schedules an update to a component's `state` object. When state changes, the component responds by re-rendering.
11+
`setState()` tworzy plan aktualizacji obiektu `state` w komponencie. Gdy stan ulega zmianie, komponent reaguje poprzez ponowne renderowanie.
1212

13-
### What is the difference between `state` and `props`? {#what-is-the-difference-between-state-and-props}
13+
### Jaka jest różnica między `state` a `props`? {#what-is-the-difference-between-state-and-props}
1414

15-
[`props`](/docs/components-and-props.html) (short for "properties") and [`state`](/docs/state-and-lifecycle.html) are both plain JavaScript objects. While both hold information that influences the output of render, they are different in one important way: `props` get passed *to* the component (similar to function parameters) whereas `state` is managed *within* the component (similar to variables declared within a function).
15+
Właściwości [`props`](/docs/components-and-props.html) (skrót od *properties*) i stan [`state`](/docs/state-and-lifecycle.html) są zwykłymi obiektami javascriptowymi. Przechowują informacje, które wpływają na wynik renderowania komponentu, jednak jest między nimi istotna różnica: właściwości `props` są przekazywane *do* komponentu (podobnie jak argumenty do funkcji), podczas gdy stan `state` jest zarządzany *wewnątrz* komponentu (podobnie jak zmienna w ciele funkcji).
1616

17-
Here are some good resources for further reading on when to use `props` vs `state`:
18-
* [Props vs State](https://github.com/uberVU/react-guide/blob/master/props-vs-state.md)
19-
* [ReactJS: Props vs. State](https://lucybain.com/blog/2016/react-state-vs-pros/)
17+
Oto kilka sprawdzonych źródeł, z których dowiesz się więcej o tym, kiedy używać właściwości `props`, a kiedy stanu `state`:
18+
* [Właściwości kontra stan](https://github.com/uberVU/react-guide/blob/master/props-vs-state.md)
19+
* [ReactJS: Właściwości kontra stan](https://lucybain.com/blog/2016/react-state-vs-pros/)
2020

21-
### Why is `setState` giving me the wrong value? {#why-is-setstate-giving-me-the-wrong-value}
21+
### Dlaczego `setState` błędnie ustawia wartość? {#why-is-setstate-giving-me-the-wrong-value}
2222

23-
In React, both `this.props` and `this.state` represent the *rendered* values, i.e. what's currently on the screen.
23+
W Reakcie zarówno `this.props`, jak i `this.state` reprezentują *wyrenderowane* wartości, tzn. te, które aktualnie widzimy na ekranie.
2424

25-
Calls to `setState` are asynchronous - don't rely on `this.state` to reflect the new value immediately after calling `setState`. Pass an updater function instead of an object if you need to compute values based on the current state (see below for details).
25+
Wywołania funkcji `setState` są asynchroniczne - nie spodziewaj się, że `this.state` będzie odzwierciedlać aktualny stan natychmiast po wywołaniu `setState`. Jeśli chcesz obliczyć nowe wartości na podstawie starych, zamiast obiektu przekaż funkcję aktualizującą (więcej o tym poniżej).
2626

27-
Example of code that will *not* behave as expected:
27+
Przykład kodu, który *nie* zachowa się tak, jak byśmy się spodziewali:
2828

2929
```jsx
3030
incrementCount() {
31-
// Note: this will *not* work as intended.
31+
// Uwaga: To *nie* zadziała tak, jak myślisz.
3232
this.setState({count: this.state.count + 1});
3333
}
3434

3535
handleSomething() {
36-
// Let's say `this.state.count` starts at 0.
36+
// Załóżmy, że `this.state.count` startuje z wartością 0.
3737
this.incrementCount();
3838
this.incrementCount();
3939
this.incrementCount();
40-
// When React re-renders the component, `this.state.count` will be 1, but you expected 3.
40+
// Kiedy React ponownie wyrenderuje ten komponent, wartość `this.state.count` będzie 1, a nie 3.
4141

42-
// This is because `incrementCount()` function above reads from `this.state.count`,
43-
// but React doesn't update `this.state.count` until the component is re-rendered.
44-
// So `incrementCount()` ends up reading `this.state.count` as 0 every time, and sets it to 1.
42+
// Dzieje się tak dlatego, że powyższa funkcja `incrementCount()` odczytuje wartość z `this.state.count`,
43+
// jednak React nie aktualizuje wartości `this.state.count`, dopóki nie nastąpi ponowne wyrenderowanie.
44+
// Dlatego `incrementCount()` za każdym razem odczyta `this.state.count` jako 0, a następnie zaplanuje zmianę na 1.
4545

46-
// The fix is described below!
46+
// Jak sobie z tym poradzić? Czytaj dalej!
4747
}
4848
```
4949

50-
See below for how to fix this problem.
50+
Poniżej znajduje się rozwiązanie tego problemu.
5151

52-
### How do I update state with values that depend on the current state? {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
52+
### Jak aktualizować stan wartościami, które zależą od aktualnego stanu? {#how-do-i-update-state-with-values-that-depend-on-the-current-state}
5353

54-
Pass a function instead of an object to `setState` to ensure the call always uses the most updated version of state (see below).
54+
Do `setState` zamiast obiektu przekaż funkcję, aby upewnić się, że do obliczeń użyta zostanie najbardziej aktualna wersja stanu (patrz niżej).
5555

56-
### What is the difference between passing an object or a function in `setState`? {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
56+
### Czym różni się przekazanie do `setState` obiektu od przekazania funkcji? {#what-is-the-difference-between-passing-an-object-or-a-function-in-setstate}
5757

58-
Passing an update function allows you to access the current state value inside the updater. Since `setState` calls are batched, this lets you chain updates and ensure they build on top of each other instead of conflicting:
58+
Przekazana funkcja aktualizująca ma dostęp do aktualnej wersji stanu. Jako że wywołania `setState` są grupowane, ten sposób pozwoli ci na stworzenie sekwencji aktualizacji, która zamiast powodować konflikty, będzie operowała na kolejnych aktualnych wersjach stanu:
5959

6060
```jsx
6161
incrementCount() {
6262
this.setState((state) => {
63-
// Important: read `state` instead of `this.state` when updating.
63+
// Ważne: zamiast z `this.state` odczytuj wartość z argumentu `state`.
6464
return {count: state.count + 1}
6565
});
6666
}
6767

6868
handleSomething() {
69-
// Let's say `this.state.count` starts at 0.
69+
// Załóżmy, że `this.state.count` startuje z wartością 0.
7070
this.incrementCount();
7171
this.incrementCount();
7272
this.incrementCount();
7373

74-
// If you read `this.state.count` now, it would still be 0.
75-
// But when React re-renders the component, it will be 3.
74+
// Jeśli sprawdzisz teraz wartość `this.state.count`, nadal będzie równa 0.
75+
// Jednak gdy React ponownie wyrenderuje komponent, zmieni się ona na 3.
7676
}
7777
```
7878

79-
[Learn more about setState](/docs/react-component.html#setstate)
79+
[Dowiedz się więcej na temat funkcji `setState`.](/docs/react-component.html#setstate)
8080

81-
### When is `setState` asynchronous? {#when-is-setstate-asynchronous}
81+
### Kiedy `setState` działa asynchronicznie? {#when-is-setstate-asynchronous}
8282

83-
Currently, `setState` is asynchronous inside event handlers.
83+
Obecnie `setState` działa asynchronicznie wewnątrz procedur obsługi zdarzeń.
8484

85-
This ensures, for example, that if both `Parent` and `Child` call `setState` during a click event, `Child` isn't re-rendered twice. Instead, React "flushes" the state updates at the end of the browser event. This results in significant performance improvements in larger apps.
85+
Dzięki temu, na przykład, jeśli zarówno komponent-rodzic, jak i komponent-dziecko wywołają `setState` podczas zdarzenia kliknięcia, komponent-dziecko nie zostanie ponownie wyrenderowany dwukrotnie. Zamiast tego React uruchomi wszystkie te aktualizacje stanu na koniec przeglądarkowego zdarzenia. W większych aplikacjach korzystnie wpływa to na wydajność.
8686

87-
This is an implementation detail so avoid relying on it directly. In the future versions, React will batch updates by default in more cases.
87+
Jest to szczegół implementacyjny i staraj się nie polegać na nim bezpośrednio. W przyszłych wersjach React będzie domyślnie grupował aktualizacje w większej liczbie przypadków.
8888

89-
### Why doesn't React update `this.state` synchronously? {#why-doesnt-react-update-thisstate-synchronously}
89+
### Dlaczego React nie aktualizuje `this.state` synchronicznie? {#why-doesnt-react-update-thisstate-synchronously}
9090

91-
As explained in the previous section, React intentionally "waits" until all components call `setState()` in their event handlers before starting to re-render. This boosts performance by avoiding unnecessary re-renders.
91+
Jak wyjaśniliśmy w poprzedniej sekcji, React celowo "czeka", aż wszystkie komponenty wywołają `setState()` w swoich procedurach obsługi zdarzeń, zanim zacznie ponownie renderować drzewo komponentów. Dzięki temu unikamy niepotrzebnych ponownych renderowań, co korzystnie wpływa na wydajność aplikacji.
9292

93-
However, you might still be wondering why React doesn't just update `this.state` immediately without re-rendering.
93+
Mimo wszystko może dziwić cię, dlaczego React tak po prostu nie aktualizuje `this.state` natychmiastowo, bez ponownego renderowania.
9494

95-
There are two main reasons:
95+
Są ku temu dwa powody:
9696

97-
* This would break the consistency between `props` and `state`, causing issues that are very hard to debug.
98-
* This would make some of the new features we're working on impossible to implement.
97+
* Skutkowałoby to przerwaniem spójności między właściwościami a stanem, powodując bardzo trudne w zlokalizowaniu błędy.
98+
* Uniemożliwiłoby to nam zaimplementowanie opracowywanych przez nas nowych funkcjonalności.
9999

100-
This [GitHub comment](https://github.com/facebook/react/issues/11527#issuecomment-360199710) dives deep into the specific examples.
100+
Ten [komentarz na GitHubie](https://github.com/facebook/react/issues/11527#issuecomment-360199710) dużo bardziej zagłębia się w konkretne przykłady.
101101

102-
### Should I use a state management library like Redux or MobX? {#should-i-use-a-state-management-library-like-redux-or-mobx}
102+
### Czy powinno się używać bibliotek zarządzających stanem, jak Redux czy MobX? {#should-i-use-a-state-management-library-like-redux-or-mobx}
103103

104-
[Maybe.](https://redux.js.org/faq/general#when-should-i-use-redux)
104+
[Być może.](https://redux.js.org/faq/general#when-should-i-use-redux)
105105

106-
It's a good idea to get to know React first, before adding in additional libraries. You can build quite complex applications using only React.
106+
Dobrze jest jednak najpierw dobrze poznać Reacta, zanim zacznie się dodawać kolejne biblioteki do zestawu. W samym tylko Reakcie można napisać dość złożone aplikacje.

0 commit comments

Comments
 (0)