|
1 | 1 | ---
|
2 | 2 | id: rendering-elements
|
3 |
| -title: Rendering Elements |
| 3 | +title: Renderowanie elementów |
4 | 4 | permalink: docs/rendering-elements.html
|
5 | 5 | redirect_from:
|
6 | 6 | - "docs/displaying-data.html"
|
7 | 7 | prev: introducing-jsx.html
|
8 | 8 | next: components-and-props.html
|
9 | 9 | ---
|
10 | 10 |
|
11 |
| -Elements are the smallest building blocks of React apps. |
| 11 | +Elementy to najmniejsze bloki budujące reactowe aplikacje. |
12 | 12 |
|
13 |
| -An element describes what you want to see on the screen: |
| 13 | +Element opisuje, co chcesz zobaczyć na ekranie: |
14 | 14 |
|
15 | 15 | ```js
|
16 |
| -const element = <h1>Hello, world</h1>; |
| 16 | +const element = <h1>Witaj, świecie!</h1>; |
17 | 17 | ```
|
18 | 18 |
|
19 |
| -Unlike browser DOM elements, React elements are plain objects, and are cheap to create. React DOM takes care of updating the DOM to match the React elements. |
| 19 | +W przeciwieństwie do elementów drzewa DOM w przeglądarce, reactowe elementy są zwykłymi obiektami i mają niski koszt tworzenia. React DOM zajmuje się aktualizowaniem drzewa DOM tak, aby odpowiadało strukturze elementów reactowych. |
20 | 20 |
|
21 |
| ->**Note:** |
| 21 | + |
| 22 | +>**Wskazówka:** |
22 | 23 | >
|
23 |
| ->One might confuse elements with a more widely known concept of "components". We will introduce components in the [next section](/docs/components-and-props.html). Elements are what components are "made of", and we encourage you to read this section before jumping ahead. |
| 24 | +>Łatwo pomylić elementy z szerzej znaną koncepcją "komponentów". Komponenty przedstawimy w [kolejnym rozdziale](/docs/components-and-props.html). Elementy są tym, z czego komponenty "są zbudowane". Zachęcamy do przeczytania tego rozdziału przed przejściem dalej. |
24 | 25 |
|
25 |
| -## Rendering an Element into the DOM {#rendering-an-element-into-the-dom} |
| 26 | +## Renderowanie elementu w drzewie DOM {#rendering-an-element-into-the-dom} |
26 | 27 |
|
27 |
| -Let's say there is a `<div>` somewhere in your HTML file: |
| 28 | +Powiedzmy, że gdzieś w twoim pliku HTML jest `<div>`: |
28 | 29 |
|
29 | 30 | ```html
|
30 | 31 | <div id="root"></div>
|
31 | 32 | ```
|
32 | 33 |
|
33 |
| -We call this a "root" DOM node because everything inside it will be managed by React DOM. |
| 34 | +Ten węzeł drzewa DOM nazywamy "korzeniem", bo wszystko, co się w nim znajduje będzie zarządzane przez React DOM. |
34 | 35 |
|
35 |
| -Applications built with just React usually have a single root DOM node. If you are integrating React into an existing app, you may have as many isolated root DOM nodes as you like. |
| 36 | +Aplikacje zbudowane przy pomocy samego Reacta zazwyczaj posiadają pojedynczy węzeł drzewa DOM. Jeśli natomiast integrujesz reactową aplikację z już istniejącą aplikacją, możesz mieć tyle odizolowanych "korzeni", ile chcesz. |
36 | 37 |
|
37 |
| -To render a React element into a root DOM node, pass both to `ReactDOM.render()`: |
| 38 | +Aby wyrenderować reactowy element w węźle drzewa DOM, przekaż oba do `ReactDOM.render()`: |
38 | 39 |
|
39 | 40 | `embed:rendering-elements/render-an-element.js`
|
40 | 41 |
|
41 | 42 | [](codepen://rendering-elements/render-an-element)
|
42 | 43 |
|
43 |
| -It displays "Hello, world" on the page. |
| 44 | +Na stronie wyświetli się napis "Witaj, świecie!". |
44 | 45 |
|
45 |
| -## Updating the Rendered Element {#updating-the-rendered-element} |
| 46 | +## Aktualizowanie wyrenderowanego elementu {#updating-the-rendered-element} |
46 | 47 |
|
47 |
| -React elements are [immutable](https://en.wikipedia.org/wiki/Immutable_object). Once you create an element, you can't change its children or attributes. An element is like a single frame in a movie: it represents the UI at a certain point in time. |
| 48 | +Reactowe elementy są [niezmienne](https://en.wikipedia.org/wiki/Immutable_object) (ang. *immutable*). Kiedy już stworzysz element, nie możesz zmienić jego komponentów potomnych ani właściwości. Element jest jak pojedyncza klatka z filmu: reprezentuje interfejs użytkownika w pewnym punkcie czasu. |
48 | 49 |
|
49 |
| -With our knowledge so far, the only way to update the UI is to create a new element, and pass it to `ReactDOM.render()`. |
| 50 | +Przy naszej dotychczasowej wiedzy, jedynym sposobem aktualizacji interfejsu użytkownika jest stworzenie nowego elementu i przekazanie go do `ReactDOM.render()`. |
50 | 51 |
|
51 |
| -Consider this ticking clock example: |
| 52 | +Rozważ ten przykład tykającego zegara: |
52 | 53 |
|
53 | 54 | `embed:rendering-elements/update-rendered-element.js`
|
54 | 55 |
|
55 | 56 | [](codepen://rendering-elements/update-rendered-element)
|
56 | 57 |
|
57 |
| -It calls `ReactDOM.render()` every second from a [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setInterval) callback. |
| 58 | +Wywołuje on `ReactDOM.render()` z wewnątrz funkcji zwrotnej [`setInterval()`](https://developer.mozilla.org/pl/docs/Web/API/Window/setInterval) co sekundę. |
58 | 59 |
|
59 |
| ->**Note:** |
| 60 | +>**Wskazówka:** |
60 | 61 | >
|
61 |
| ->In practice, most React apps only call `ReactDOM.render()` once. In the next sections we will learn how such code gets encapsulated into [stateful components](/docs/state-and-lifecycle.html). |
| 62 | +>W praktyce większość reactowych aplikacji wywołuje `ReactDOM.render()` tylko raz. W kolejnych rozdziałach dowiemy się, jak można taki kod wyizolować do [komponentów stanowych](/docs/state-and-lifecycle.html). |
62 | 63 | >
|
63 |
| ->We recommend that you don't skip topics because they build on each other. |
| 64 | +>Radzimy jednak nie pomijać żadnych tematów, ponieważ kolejne rozdziały oparte są o wiedzę z poprzednich. |
64 | 65 |
|
65 |
| -## React Only Updates What's Necessary {#react-only-updates-whats-necessary} |
| 66 | +## React uaktualnia tylko to, co potrzebne {#react-only-updates-whats-necessary} |
66 | 67 |
|
67 |
| -React DOM compares the element and its children to the previous one, and only applies the DOM updates necessary to bring the DOM to the desired state. |
| 68 | +React DOM porównuje element i jego potomków do poprzedniego oraz nakłada tylko te aktualizacje drzewa DOM, które konieczne są do doprowadzenia go do pożądanego stanu. |
68 | 69 |
|
69 |
| -You can verify by inspecting the [last example](codepen://rendering-elements/update-rendered-element) with the browser tools: |
| 70 | +Możesz to sprawdzić przez zbadanie (ang. *inspect*) [ostatniego przykładu](codepen://rendering-elements/update-rendered-element) przy użyciu narzędzi deweloperskich: |
70 | 71 |
|
71 |
| - |
| 72 | + |
72 | 73 |
|
73 |
| -Even though we create an element describing the whole UI tree on every tick, only the text node whose contents has changed gets updated by React DOM. |
| 74 | +Mimo że przy każdym tyknięciu zegara tworzymy element opisujący cały interfejs użytkownika, tylko węzeł tekstowy, którego treść uległa zmianie, zostaje zaktualizowany przez React DOM. |
74 | 75 |
|
75 |
| -In our experience, thinking about how the UI should look at any given moment rather than how to change it over time eliminates a whole class of bugs. |
| 76 | +Według naszego doświadczenia, myślenie o tym, jak powinien wyglądać interfejs użytkownika w danym momencie, a nie jak zmieniać go w czasie, eliminuje całą klasę błędów. |
0 commit comments