From 26b11018922785415854354a0f14099d206b2c47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rado=C5=A1=20Mili=C4=87ev?= <40705899+rammba@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:35:24 +0100 Subject: [PATCH] Translate responding-to-events.md --- src/content/learn/adding-interactivity.md | 12 +- .../learn/passing-props-to-a-component.md | 2 +- src/content/learn/responding-to-events.md | 306 +++++++++--------- 3 files changed, 160 insertions(+), 160 deletions(-) diff --git a/src/content/learn/adding-interactivity.md b/src/content/learn/adding-interactivity.md index a3f0f6f7..128b330f 100644 --- a/src/content/learn/adding-interactivity.md +++ b/src/content/learn/adding-interactivity.md @@ -10,7 +10,7 @@ Neke stvari na ekranu se update-uju kao odgovor na korisnički unos. Na primer, -* [Kako da rukujette event-ima koje pokrene korisnik](/learn/responding-to-events) +* [Kako da rukujete event-ima koje pokrene korisnik](/learn/responding-to-events) * [Kako da učinite da component-e „pamte” informacije koristeći state](/learn/state-a-components-memory) * [Kako React update-uje UI u dve faze](/learn/render-and-commit) * [Zašto se state ne update-uje odmah nakon promene](/learn/state-as-a-snapshot) @@ -22,7 +22,7 @@ Neke stvari na ekranu se update-uju kao odgovor na korisnički unos. Na primer, ## Odgovaranje na event-e {/*responding-to-events*/} -React vam omogućava da dodate *event handler*-e u vaš JSX. Event handler-i su vaše sopstvene funkcije koje će se pokrenuti kao odgovor na korisničke interakcije, poput klika, prelaženja mišem, fokusiranja na form input-e i tako dalje. +React vam omogućava da dodate *event handler*-e u vaš JSX. Event handler-i su vaše sopstvene funkcije koje će se pokrenuti kao odgovor na korisničke interakcije poput klika, prelaženja mišem, fokusiranja na input-e forme i tako dalje. Ugrađene component-e poput ` ); diff --git a/src/content/learn/passing-props-to-a-component.md b/src/content/learn/passing-props-to-a-component.md index 61306a68..59c4579e 100644 --- a/src/content/learn/passing-props-to-a-component.md +++ b/src/content/learn/passing-props-to-a-component.md @@ -347,7 +347,7 @@ export function getImageUrl(person, size = 's') { -Pokušajte da promenite `` unutar ``-a sa nekim tekstom da biste videli kako `Card` komponenta može da obmota bilo koji ugnježdeni sadržaj. Ona ne mora da "zna" šta će biti renderovano unutar nje. Videćete ovaj fleksibilni obrazac na mnogim mestima. +Pokušajte da promenite `` unutar ``-a sa nekim tekstom da biste videli kako `Card` komponenta može da obmota bilo koji ugnježdeni sadržaj. Ona ne mora da "zna" šta će biti renderovano unutar nje. Videćete ovaj fleksibilni šablon na mnogim mestima. Komponentu sa `children` prop možete zamisliti kao da ima "šupljinu" koja će biti "popunjena" u njenim roditeljskim komponentama sa proizvoljnim JSX-om. Često ćete koristiti `children` prop za vizuelne wrapper-e: panel-e, grid-ove, itd. diff --git a/src/content/learn/responding-to-events.md b/src/content/learn/responding-to-events.md index 17bd087e..9ea8cbb6 100644 --- a/src/content/learn/responding-to-events.md +++ b/src/content/learn/responding-to-events.md @@ -1,24 +1,24 @@ --- -title: Responding to Events +title: Odgovaranje na event-e --- -React lets you add *event handlers* to your JSX. Event handlers are your own functions that will be triggered in response to interactions like clicking, hovering, focusing form inputs, and so on. +React vam omogućava da dodate *event handler*-e u vaš JSX. Event handler-i su vaše sopstvene funkcije koje će se pokrenuti kao odgovor na korisničke interakcije poput klika, prelaženja mišem, fokusiranja na input-e forme i tako dalje. -* Different ways to write an event handler -* How to pass event handling logic from a parent component -* How events propagate and how to stop them +* Različite načine da napišete event handler +* Kako proslediti logiku za obrađivanje event-ova iz roditeljske komponente +* Kako se event-i propagiraju i kako ih zaustaviti -## Adding event handlers {/*adding-event-handlers*/} +## Dodavanje event handler-a {/*adding-event-handlers*/} -To add an event handler, you will first define a function and then [pass it as a prop](/learn/passing-props-to-a-component) to the appropriate JSX tag. For example, here is a button that doesn't do anything yet: +Da biste dodali event handler, prvo ćete definisati funkciju, a onda je [proslediti kao prop](/learn/passing-props-to-a-component) u odgovarajući JSX tag. Na primer, ovde je dugme koje još uvek ništa ne radi: @@ -26,7 +26,7 @@ To add an event handler, you will first define a function and then [pass it as a export default function Button() { return ( ); } @@ -34,23 +34,23 @@ export default function Button() { -You can make it show a message when a user clicks by following these three steps: +Možete učiniti da se prikaže poruka kad ga korisnik klikne prateći ova tri koraka: -1. Declare a function called `handleClick` *inside* your `Button` component. -2. Implement the logic inside that function (use `alert` to show the message). -3. Add `onClick={handleClick}` to the ` ); } @@ -62,77 +62,77 @@ button { margin-right: 10px; } -You defined the `handleClick` function and then [passed it as a prop](/learn/passing-props-to-a-component) to ` ); } function UploadButton() { return ( - ); } @@ -207,7 +207,7 @@ function UploadButton() { export default function Toolbar() { return (
- +
); @@ -220,22 +220,22 @@ button { margin-right: 10px; } -Here, the `Toolbar` component renders a `PlayButton` and an `UploadButton`: +Ovde, `Toolbar` komponenta renderuje `PlayButton` i `UploadButton`: -- `PlayButton` passes `handlePlayClick` as the `onClick` prop to the `Button` inside. -- `UploadButton` passes `() => alert('Uploading!')` as the `onClick` prop to the `Button` inside. +- `PlayButton` prosleđuje `handlePlayClick` kao `onClick` prop u `Button` komponentu. +- `UploadButton` prosleđuje `() => alert('Upload-ovanje!')` kao `onClick` prop u `Button` komponentu. -Finally, your `Button` component accepts a prop called `onClick`. It passes that prop directly to the built-in browser ` - ); @@ -268,9 +268,9 @@ button { margin-right: 10px; } -In this example, ` ); @@ -312,19 +312,19 @@ button { margin-right: 10px; } -Notice how the `App` component does not need to know *what* `Toolbar` will do with `onPlayMovie` or `onUploadImage`. That's an implementation detail of the `Toolbar`. Here, `Toolbar` passes them down as `onClick` handlers to its `Button`s, but it could later also trigger them on a keyboard shortcut. Naming props after app-specific interactions like `onPlayMovie` gives you the flexibility to change how they're used later. +Primetite da `App` komponenta ne mora da zna *šta* će `Toolbar` uraditi sa `onPlayMovie` i `onUploadImage`. To je implementacijski detalj u `Toolbar`-u. Takođe, `Toolbar` ih prosleđuje kao `onClick` handler-e u svoje `Button`-e, ali ih kasnije može okinuti i za prečicu na tastaturi. Imenovanje event handler props-a na osnovu koncepata specifičnih za aplikaciju poput `onPlayMovie` vam daje fleksibilnost da kasnije menjate kako se koriste. -Make sure that you use the appropriate HTML tags for your event handlers. For example, to handle clicks, use [` - ); @@ -355,19 +355,19 @@ button { margin: 5px; } -If you click on either button, its `onClick` will run first, followed by the parent `
`'s `onClick`. So two messages will appear. If you click the toolbar itself, only the parent `
`'s `onClick` will run. +Ako kliknete na neko dugme, prvo će se izvršiti njegov `onClick`, a nakon toga i `onClick` od roditeljskog `
`-a. Znači, dve poruke će se prikazati. Ako kliknete samo na toolbar, samo će se izvršiti `onClick` na `
`-u. -All events propagate in React except `onScroll`, which only works on the JSX tag you attach it to. +U React-u, svi event-i se propagiraju osim `onScroll`, koji radi samo za JSX tag na kom je definisan. -### Stopping propagation {/*stopping-propagation*/} +### Zaustavljanje propagacije {/*stopping-propagation*/} -Event handlers receive an **event object** as their only argument. By convention, it's usually called `e`, which stands for "event". You can use this object to read information about the event. +Event handler-i primaju **event objekat** kao jedini argument. Po konvenciji, često se naziva `e`, što označava "event". Možete koristiti ovaj objekat da čitate informacije o event-u. -That event object also lets you stop the propagation. If you want to prevent an event from reaching parent components, you need to call `e.stopPropagation()` like this `Button` component does: +Ovaj event objekat vam takođe omogućava da zaustavite propagaciju. Ako želite da sprečite event da dospe do roditeljskih komponenata, morate pozvati `e.stopPropagation()` kao što to radi `Button` komponenta: @@ -386,13 +386,13 @@ function Button({ onClick, children }) { export default function Toolbar() { return (
{ - alert('You clicked on the toolbar!'); + alert('Kliknuli ste na toolbar!'); }}> - -
); @@ -409,43 +409,43 @@ button { margin: 5px; }
-When you click on a button: +Kada kliknete na dugme: -1. React calls the `onClick` handler passed to `
``` -Each event propagates in three phases: +Svaki event se propagira u tri faze: -1. It travels down, calling all `onClickCapture` handlers. -2. It runs the clicked element's `onClick` handler. -3. It travels upwards, calling all `onClick` handlers. +1. Putuje na dole, pozivajući sve `onClickCapture` handler-e. +2. Pokreće `onClick` handler na kliknutom elementu. +3. Putuje na gore, pozivajući sve `onClick` handler-e. -Capture events are useful for code like routers or analytics, but you probably won't use them in app code. +Capture event-i su korisni za rutere i analitiku, ali ih verovatno nećete koristiti u kodu aplikacije. -### Passing handlers as alternative to propagation {/*passing-handlers-as-alternative-to-propagation*/} +### Prosleđivanje handler-a kao alternative za propagaciju {/*passing-handlers-as-alternative-to-propagation*/} -Notice how this click handler runs a line of code _and then_ calls the `onClick` prop passed by the parent: +Primetite da ovaj klik handler pokreće liniju koda, _a onda_ poziva `onClick` prop prosleđen iz roditelja: ```js {4,5} function Button({ onClick, children }) { @@ -460,22 +460,22 @@ function Button({ onClick, children }) { } ``` -You could add more code to this handler before calling the parent `onClick` event handler, too. This pattern provides an *alternative* to propagation. It lets the child component handle the event, while also letting the parent component specify some additional behavior. Unlike propagation, it's not automatic. But the benefit of this pattern is that you can clearly follow the whole chain of code that executes as a result of some event. +Takođe, možete dodati još koda u ovaj handler pre poziva roditeljskog `onClick` event handler-a. Ovaj šablon pruža *alternativu* propagaciji. Omogućava dečjoj komponenti da obradi event, dopuštajući roditeljskoj komponenti da specificira i neko dodatno ponašanje. Za razliku od propagacije, ovo nije automatsko. Međutim, benefit ovog šablona je da jasno možete ispratiti sav kod koji se izvršava kao rezultat nekog event-a. -If you rely on propagation and it's difficult to trace which handlers execute and why, try this approach instead. +Ako se oslanjate na propagaciju i teško vam je da ispratite koji handler-i se izvršavaju i zašto, probajte ovaj pristup. -### Preventing default behavior {/*preventing-default-behavior*/} +### Sprečavanje default ponašanja {/*preventing-default-behavior*/} -Some browser events have default behavior associated with them. For example, a `
` submit event, which happens when a button inside of it is clicked, will reload the whole page by default: +Neki event-i u pretraživačima imaju default ponašanje. Na primer, `` submit event, koji se okida kada se klikne dugme unutar forme, ponovo će učitati celu stranicu po default-u: ```js export default function Signup() { return ( - alert('Submitting!')}> + alert('Submit-ovanje!')}> - + ); } @@ -487,7 +487,7 @@ button { margin-left: 5px; }
-You can call `e.preventDefault()` on the event object to stop this from happening: +Možete pozvati `e.preventDefault()` nad event objektom kako biste zaustavili ovo: @@ -496,10 +496,10 @@ export default function Signup() { return (
{ e.preventDefault(); - alert('Submitting!'); + alert('Submit-ovanje!'); }}> - +
); } @@ -511,28 +511,28 @@ button { margin-left: 5px; }
-Don't confuse `e.stopPropagation()` and `e.preventDefault()`. They are both useful, but are unrelated: +Nemojte pomešati `e.stopPropagation()` i `e.preventDefault()`. Korisni su, ali nisu povezani: -* [`e.stopPropagation()`](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation) stops the event handlers attached to the tags above from firing. -* [`e.preventDefault()` ](https://developer.mozilla.org/docs/Web/API/Event/preventDefault) prevents the default browser behavior for the few events that have it. +* [`e.stopPropagation()`](https://developer.mozilla.org/docs/Web/API/Event/stopPropagation) zaustavlja okidanje event handler-a povezanih sa tag-ovima iznad u hijerarhiji. +* [`e.preventDefault()`](https://developer.mozilla.org/docs/Web/API/Event/preventDefault) sprečava default ponašanje pretraživača za par event-ova koji ga imaju. -## Can event handlers have side effects? {/*can-event-handlers-have-side-effects*/} +## Da li event handler-i smeju imati propratne efekte? {/*can-event-handlers-have-side-effects*/} -Absolutely! Event handlers are the best place for side effects. +Apsolutno! Event handler-i su najbolje mesto za propratne efekte. -Unlike rendering functions, event handlers don't need to be [pure](/learn/keeping-components-pure), so it's a great place to *change* something—for example, change an input's value in response to typing, or change a list in response to a button press. However, in order to change some information, you first need some way to store it. In React, this is done by using [state, a component's memory.](/learn/state-a-components-memory) You will learn all about it on the next page. +Za razliku od funkcija za renderovanje, event handler-i ne moraju biti [čisti](/learn/keeping-components-pure), tako da su odlično mesto za *promenu* nečega—na primer, promena input vrednosti kao rezultat kucanja, ili promena liste kao odgovor na klik dugmeta. Međutim, da biste izmenili neku informaciju, prvo vam je potreban način da je čuvate. U React-u, to se dešava kroz [state, memoriju komponente](/learn/state-a-components-memory). Naučićete sve o tome na narednoj stranici. -* You can handle events by passing a function as a prop to an element like ` ); } @@ -569,7 +569,7 @@ export default function LightSwitch() { -The problem is that ` ); } @@ -594,7 +594,7 @@ export default function LightSwitch() { -Alternatively, you could wrap the call into another function, like ` ); } @@ -621,11 +621,11 @@ export default function LightSwitch() { -#### Wire up the events {/*wire-up-the-events*/} +#### Povezati event-e {/*wire-up-the-events*/} -This `ColorSwitch` component renders a button. It's supposed to change the page color. Wire it up to the `onChangeColor` event handler prop it receives from the parent so that clicking the button changes the color. +Ova `ColorSwitch` komponenta renderuje dugme. Trebala bi da promeni boju na stranici. Povežite je sa `onChangeColor` event handler prop-om koji dobija od roditelja, kako biste klikom na dugme menjali boju. -After you do this, notice that clicking the button also increments the page click counter. Your colleague who wrote the parent component insists that `onChangeColor` does not increment any counters. What else might be happening? Fix it so that clicking the button *only* changes the color, and does _not_ increment the counter. +Nakon što to uradite, primetite da klikom na dugme povećavate i brojač klikova na stranici. Vaš kolega koji je napisao roditeljsku komponentu insistira da `onChangeColor` ne povećava nijedan brojač. Šta se još može dogoditi? Popravite ovo tako da klik na dugme *jedino* menja boju, a _ne_ povećava brojač. @@ -635,7 +635,7 @@ export default function ColorSwitch({ }) { return ( ); } @@ -669,7 +669,7 @@ export default function App() {

-

Clicks on the page: {clicks}

+

Klikova na stranici: {clicks}

); } @@ -679,9 +679,9 @@ export default function App() { -First, you need to add the event handler, like ` ); } @@ -728,7 +728,7 @@ export default function App() {

-

Clicks on the page: {clicks}

+

Klikova na stranici: {clicks}

); }