Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7ad9cd5
Translate Intro and Reference
dawidsabat Aug 20, 2023
3594db2
Minor fixes based on comments from previous PR
dawidsabat Aug 25, 2023
bf77393
Translate Usage: Connecting to an external system
dawidsabat Aug 25, 2023
b7dd7a1
Translate Usage: Connecting to an external system - examples
dawidsabat Aug 25, 2023
db02fca
Merge branch 'main' into Reference_useEffect
dawidsabat Aug 25, 2023
232f59c
Translate Usage: Wrapping Effects in custom Hooks
dawidsabat Aug 26, 2023
a2bab77
Translate Usage: Controlling a non-React widget
dawidsabat Aug 26, 2023
726c31c
Fix minor issues
dawidsabat Aug 28, 2023
693c7c8
Translage Usage: Fetching data with effects
dawidsabat Aug 28, 2023
fec3703
Translate Usage: Specifying reactive dependencies
dawidsabat Aug 28, 2023
e5ef8ed
Translate Usage: Specifying reactive dependencies: Examples
dawidsabat Aug 29, 2023
6df116b
Translate Usage: Updating state based on previous state
dawidsabat Aug 29, 2023
b0cbf5b
Translate Usage: Removing unnecessary object dependencies
dawidsabat Aug 29, 2023
d06739c
Translate Usage: Removing unnecessary function dependencies
dawidsabat Aug 29, 2023
627d80a
Translate Usage: Reading the latest props and state from an Effect
dawidsabat Aug 30, 2023
544f1a5
Translate Troubleshooting: My Effect runs twice
dawidsabat Aug 30, 2023
a85b38d
Merge branch 'main' into Reference_useEffect
dawidsabat Sep 20, 2023
cb58df8
Minor fix
dawidsabat Oct 1, 2023
a983b0a
Merge branch 'main' into Reference_useEffect
dawidsabat Oct 1, 2023
fc7268c
displaying-different-content-on-the-server-and-the-client
dawidsabat Oct 1, 2023
9dbabf8
Fix effect event translation
dawidsabat Oct 2, 2023
b0022fb
Fix minor translation
dawidsabat Oct 2, 2023
947222c
my-effect-runs-after-every-re-render
dawidsabat Oct 2, 2023
28e3cd4
my-effect-keeps-re-running-in-an-infinite-cycle
dawidsabat Oct 5, 2023
600993a
Fix typos
dawidsabat Oct 5, 2023
2cd24dd
Fix hydration translations.
dawidsabat Oct 5, 2023
5e2efba
my-cleanup-logic-runs-even-though-my-component-didnt-unmount
dawidsabat Oct 5, 2023
5029e8b
my-effect-does-something-visual
dawidsabat Oct 5, 2023
f9b7d6c
Fix casing
dawidsabat Oct 5, 2023
93cd2c8
Fix typos
dawidsabat Oct 5, 2023
3df5584
Merge branch 'main' into Reference_useEffect
dawidsabat Oct 6, 2023
3ffe56b
Fix casing
dawidsabat Oct 6, 2023
2cfb5c1
Fix translations of setup function
dawidsabat Oct 6, 2023
babe7cc
Merge branch 'main' into Reference_useEffect
dawidsabat Oct 6, 2023
5803404
Apply suggestions from code review
dawidsabat Oct 7, 2023
b02393d
Remove exclamation marks from code examples
dawidsabat Oct 7, 2023
524af1b
Fix rest of setup function translations
dawidsabat Oct 7, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Translate Intro and Reference
  • Loading branch information
dawidsabat committed Aug 20, 2023
commit 7ad9cd5aac01782817e0295ef081eb911abb0fcb
36 changes: 18 additions & 18 deletions src/content/reference/react/useEffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: useEffect

<Intro>

`useEffect` is a React Hook that lets you [synchronize a component with an external system.](/learn/synchronizing-with-effects)
`useEffect` to hook reactowy, który pozwala [synchronizować komponent z zewnętrznym systemem.](/learn/synchronizing-with-effects)

```js
useEffect(setup, dependencies?)
Expand All @@ -16,11 +16,11 @@ useEffect(setup, dependencies?)

---

## Reference {/*reference*/}
## Dokumentacja {/*reference*/}

### `useEffect(setup, dependencies?)` {/*useeffect*/}

Call `useEffect` at the top level of your component to declare an Effect:
Aby zadeklarować Efekt, wywołaj `useEffect` na głównym poziomie swojego komponentu:

```js
import { useEffect } from 'react';
Expand All @@ -40,33 +40,33 @@ function ChatRoom({ roomId }) {
}
```

[See more examples below.](#usage)
[Zobacz więcej przykładów poniżej](#usage)

#### Parameters {/*parameters*/}
#### Parametry {/*parameters*/}

* `setup`: The function with your Effect's logic. Your setup function may also optionally return a *cleanup* function. When your component is added to the DOM, React will run your setup function. After every re-render with changed dependencies, React will first run the cleanup function (if you provided it) with the old values, and then run your setup function with the new values. After your component is removed from the DOM, React will run your cleanup function.

* **optional** `dependencies`: The list of all reactive values referenced inside of the `setup` code. Reactive values include props, state, and all the variables and functions declared directly inside your component body. If your linter is [configured for React](/learn/editor-setup#linting), it will verify that every reactive value is correctly specified as a dependency. The list of dependencies must have a constant number of items and be written inline like `[dep1, dep2, dep3]`. React will compare each dependency with its previous value using the [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is) comparison. If you omit this argument, your Effect will re-run after every re-render of the component. [See the difference between passing an array of dependencies, an empty array, and no dependencies at all.](#examples-dependencies)
* `setup`: funkcja z logiką Efektu. Funkcja `setup` może również opcjonalnie zwracać *funkcję czyszczącą* (ang. *cleanup function*). Gdy komponent zostaje dodany do DOM-u, React uruchamia funkcję `setup`. Po każdym ponownym renderowaniu z zmienionymi zależnościami, React najpierw uruchamia funkcję czyszczącą (jeśli została zdefiniowana) z poprzednimi wartościami, a następnie uruchamia funkcję `setup` z nowymi wartościami. Gdy komponent zostanie usunięty z DOM-u, react uruchamia funkcję czyszczącą.

#### Returns {/*returns*/}
* **opcjonalnie** `dependencies`: lista wszystkich reaktywnych wartości użytych w kodzie funkcji `setup`. Wartościami reaktywnymi są między innymi właściwości, stany oraz wszystkie zmienne i funkcje zadeklarowane bezpośrednio w ciele twojego komponentu. Jeśli twój linter jest [skonfigurowany pod Reacta](/learn/editor-setup#linting), będzie on sprawdzał, czy każda wartość reaktywna jest poprawnie dodana do zależności. Lista zależności musi mieć stałą liczbę elementów i być zapisana w wprost, np. `[dep1, dep2, dep3]`. React porównuje każdą zależność ze swoją poprzednią wartością, używając porównania [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is). Jeśli pominiesz ten parametr, Efekt zostanie uruchomiony ponownie po każdym przerenderowaniu komponentu. [Zobacz różnicę między przekazywaniem tablicy zależności, pustej tablicy a brakiem zależności w ogóle.](#examples-dependencies)

`useEffect` returns `undefined`.
#### Zwracana wartość {/*returns*/}

#### Caveats {/*caveats*/}
`useEffect` zwraca `undefined`.

* `useEffect` is a Hook, so you can only call it **at the top level of your component** or your own Hooks. You can't call it inside loops or conditions. If you need that, extract a new component and move the state into it.
#### Zastrzeżenia {/*caveats*/}

* If you're **not trying to synchronize with some external system,** [you probably don't need an Effect.](/learn/you-might-not-need-an-effect)
* `useEffect` jest hookiem, więc można go wywoływać tylko **na głównym poziomie komponentu** lub w innych hookach. Nie można go wywoływać wewnątrz pętli czy instrukcji warunkowej. Jeśli tego potrzebujesz, wyodrębnij nowy komponent i przenieś stan do niego.

* When Strict Mode is on, React will **run one extra development-only setup+cleanup cycle** before the first real setup. This is a stress-test that ensures that your cleanup logic "mirrors" your setup logic and that it stops or undoes whatever the setup is doing. If this causes a problem, [implement the cleanup function.](/learn/synchronizing-with-effects#how-to-handle-the-effect-firing-twice-in-development)
* Jeśli **nie próbujesz synchronizować się z jakimś zewnętrznym systemem,** [prawdopodobnie nie potrzebujesz Efektu.](/learn/you-might-not-need-an-effect)

* If some of your dependencies are objects or functions defined inside the component, there is a risk that they will **cause the Effect to re-run more often than needed.** To fix this, remove unnecessary [object](#removing-unnecessary-object-dependencies) and [function](#removing-unnecessary-function-dependencies) dependencies. You can also [extract state updates](#updating-state-based-on-previous-state-from-an-effect) and [non-reactive logic](#reading-the-latest-props-and-state-from-an-effect) outside of your Effect.
* W Trybie Restrykcyjnym (ang. *Strict Mode*), React **w środowisku developerskim wywoła dodatkowo funkcje `setup` i funkcję czyszczącą** jeszcze przed pierwszym właściwym wywołaniem `setup`. Jest to rodzaj testu, który pozwala upewnić się, że logika funkcji czyszczącej "odzwierciedla" logikę funkcji `setup` i że zatrzymuje lub cofa to, co ona robi. Jeśli to powoduje problemy, [zaimplementuj funkcję czyszczącą.](/learn/synchronizing-with-effects#how-to-handle-the-effect-firing-twice-in-development)

* If your Effect wasn't caused by an interaction (like a click), React will let the browser **paint the updated screen first before running your Effect.** If your Effect is doing something visual (for example, positioning a tooltip), and the delay is noticeable (for example, it flickers), replace `useEffect` with [`useLayoutEffect`.](/reference/react/useLayoutEffect)
* Jeśli niektóre z twoich zależności to obiekty lub funkcje zdefiniowane wewnątrz komponentu, istnieje ryzyko, że **sprawią one, że Efekt będzie wykonywał się częściej niż jest to potrzebne.** Aby to naprawić, usuń zbędne zależności od [obiektów](#removing-unnecessary-object-dependencies) i [funkcji](#removing-unnecessary-function-dependencies). Możesz również [wydzielić aktualizacje stanu](#updating-state-based-on-previous-state-from-an-effect) oraz [logikę niereaktywną](#reading-the-latest-props-and-state-from-an-effect) poza Efekt.

* Even if your Effect was caused by an interaction (like a click), **the browser may repaint the screen before processing the state updates inside your Effect.** Usually, that's what you want. However, if you must block the browser from repainting the screen, you need to replace `useEffect` with [`useLayoutEffect`.](/reference/react/useLayoutEffect)
* Jeśli twój Efekt nie został wywołany przez interakcję (np. kliknięcie), React pozwoli przeglądarce **najpierw odświeżyć ekran przed uruchomieniem twojego Efektu.** Jeśli twój Efekt wykonuje jakieś operacje związane z wyświetlaniem (np. ustawianie pozycji podpowiedzi (ang. *tooltip*)) i opóźnienie jest zauważalne (np. występuje migotanie), zastąp `useEffect` przez [`useLayoutEffect`.](/reference/react/useLayoutEffect)

* Effects **only run on the client.** They don't run during server rendering.
* Nawet jeśli twój Efekt został wywołany przez interakcję (np. kliknięcie), **przeglądarka może odświeżyć ekran przed przetworzeniem aktualizacji stanu wewnątrz twojego Efektu.** Zazwyczaj jest to pożądane zachowanie. Niemniej jednak, jeśli cheesz zablokować przeglądarkę przed odświeżaniem ekranu, musisz zastąpić `useEffect` przez [`useLayoutEffect`.](/reference/react/useLayoutEffect)

* Efekty uruchamiane są **tylko po stronie klienta.** Nie są uruchamiane podczas renderowania po stronie serwera.

---

Expand Down