Skip to content

Commit 7c25a2d

Browse files
Merge pull request #77 from shmesa22/handling-events-translation
Translate: handling events docs
2 parents 235fad4 + 604ea1c commit 7c25a2d

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

content/docs/handling-events.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
---
22
id: handling-events
3-
title: Handling Events
3+
title: Manejando Eventos
44
permalink: docs/handling-events.html
55
prev: state-and-lifecycle.html
66
next: conditional-rendering.html
77
redirect_from:
88
- "docs/events-ko-KR.html"
99
---
1010

11-
Handling events with React elements is very similar to handling events on DOM elements. There are some syntactic differences:
11+
Manejar eventos en elementos de React es muy similar a manejar eventos con elementos del DOM. Hay algunas diferencias de sintaxis:
1212

13-
* React events are named using camelCase, rather than lowercase.
14-
* With JSX you pass a function as the event handler, rather than a string.
13+
* Los eventos de React se nombran usando camelCase, en vez de minúsculas.
14+
* Con JSX pasas una función como el manejador del evento, en vez de un string.
1515

16-
For example, the HTML:
16+
Por ejemplo, el HTML:
1717

1818
```html
1919
<button onclick="activateLasers()">
2020
Activate Lasers
2121
</button>
2222
```
2323

24-
is slightly different in React:
24+
En React es algo diferente:
2525

2626
```js{1}
2727
<button onClick={activateLasers}>
2828
Activate Lasers
2929
</button>
3030
```
3131

32-
Another difference is that you cannot return `false` to prevent default behavior in React. You must call `preventDefault` explicitly. For example, with plain HTML, to prevent the default link behavior of opening a new page, you can write:
32+
Otra diferencia es que en React no puedes retornar `false` para prevenir el comportamiento por defecto. Debes, explícitamente, llamar `preventDefault`. Por ejemplo, en un HTML plano, para prevenir el comportamiento por defecto de un enlace de abrir una nueva página, puedes escribir:
3333

3434
```html
3535
<a href="#" onclick="console.log('The link was clicked.'); return false">
3636
Click me
3737
</a>
3838
```
3939

40-
In React, this could instead be:
40+
En cambio en React, esto podría ser:
4141

4242
```js{2-5,8}
4343
function ActionLink() {
@@ -54,19 +54,19 @@ function ActionLink() {
5454
}
5555
```
5656

57-
Here, `e` is a synthetic event. React defines these synthetic events according to the [W3C spec](https://www.w3.org/TR/DOM-Level-3-Events/), so you don't need to worry about cross-browser compatibility. See the [`SyntheticEvent`](/docs/events.html) reference guide to learn more.
57+
Aquí, `e` es un evento sintético. React define estos eventos sintéticos acorde a las [especificaciones W3C](https://www.w3.org/TR/DOM-Level-3-Events/), entonces no debes preocuparte por la compatibilidad a tráves de los navegadores. Mira la guía de referencia [`SyntheticEvent`](/docs/events.html) para aprender más.
5858

59-
When using React you should generally not need to call `addEventListener` to add listeners to a DOM element after it is created. Instead, just provide a listener when the element is initially rendered.
59+
Cuando estás utilizando React, generalmente, no debes llamar `addEventListener` para agregar escuchadores de eventos a un elemento del DOM después de que este es creado. Por el contrario, solo debes proveer un manejador de eventos cuando el elemento es inicialmente renderizado.
6060

61-
When you define a component using an [ES6 class](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Classes), a common pattern is for an event handler to be a method on the class. For example, this `Toggle` component renders a button that lets the user toggle between "ON" and "OFF" states:
61+
Cuando defines un componente usando una [clase de ES6](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Classes), un patrón muy común es que los manejadores de eventos sean un método de la clase. Por ejemplo, este componente `Toggle` renderiza un botón que permite al usuario cambiar el estado entre "ENCENDIDO" y "APAGADO":
6262

6363
```js{6,7,10-14,18}
6464
class Toggle extends React.Component {
6565
constructor(props) {
6666
super(props);
6767
this.state = {isToggleOn: true};
6868
69-
// This binding is necessary to make `this` work in the callback
69+
// Este enlace es necesario para hacer que `this` funcione en el callback
7070
this.handleClick = this.handleClick.bind(this);
7171
}
7272
@@ -91,18 +91,18 @@ ReactDOM.render(
9191
);
9292
```
9393

94-
[**Try it on CodePen**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010)
94+
[**Pruébalo en CodePen**](http://codepen.io/gaearon/pen/xEmzGg?editors=0010)
9595

96-
You have to be careful about the meaning of `this` in JSX callbacks. In JavaScript, class methods are not [bound](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind) by default. If you forget to bind `this.handleClick` and pass it to `onClick`, `this` will be `undefined` when the function is actually called.
96+
Tienes que tener mucho cuidado en cuanto al significado de `this` en los callbacks de JSX. En JavaScript, los métodos de clase no están [ligados](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_objects/Function/bind) por defecto. Si olvidas ligar `this.handleClick` y lo pasas a `onClick`, `this` sera `undefined` cuando se llame la función.
9797

98-
This is not React-specific behavior; it is a part of [how functions work in JavaScript](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/). Generally, if you refer to a method without `()` after it, such as `onClick={this.handleClick}`, you should bind that method.
98+
Esto no es un comportamiento especifico de React; esto hace parte de [como operan las funciones JavaScript](https://www.smashingmagazine.com/2014/01/understanding-javascript-function-prototype-bind/). Generalmente, si refieres un método sin usar `()` después de este, tal como `onClick={this.handleClick}`, deberías ligar ese método.
9999

100-
If calling `bind` annoys you, there are two ways you can get around this. If you are using the experimental [public class fields syntax](https://babeljs.io/docs/plugins/transform-class-properties/), you can use class fields to correctly bind callbacks:
100+
Si te molesta llamar `bind`, existen dos maneras de evitarlo. Si usas la sintaxis experimental [campos publicos de clases](https://babeljs.io/docs/plugins/transform-class-properties/), puedes usar los campos de clases para ligar los callbacks correctamente:
101101

102102
```js{2-6}
103103
class LoggingButton extends React.Component {
104-
// This syntax ensures `this` is bound within handleClick.
105-
// Warning: this is *experimental* syntax.
104+
// Esta sintaxis nos asegura que `this` esta ligado dentro de handleClick
105+
// Peligro: esto es una sintaxis *experimental*
106106
handleClick = () => {
107107
console.log('this is:', this);
108108
}
@@ -117,9 +117,9 @@ class LoggingButton extends React.Component {
117117
}
118118
```
119119

120-
This syntax is enabled by default in [Create React App](https://github.com/facebookincubator/create-react-app).
120+
Esta sintaxis está habilitada por defecto en [Create React App](https://github.com/facebookincubator/create-react-app).
121121

122-
If you aren't using class fields syntax, you can use an [arrow function](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) in the callback:
122+
Si no estas usando la sintaxis de campos publicos de clases, puedes usar una [función flecha](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) en el callback:
123123

124124
```js{7-9}
125125
class LoggingButton extends React.Component {
@@ -128,7 +128,7 @@ class LoggingButton extends React.Component {
128128
}
129129
130130
render() {
131-
// This syntax ensures `this` is bound within handleClick
131+
// Esta sintaxis nos asegura que `this` esta ligado dentro de handleClick
132132
return (
133133
<button onClick={(e) => this.handleClick(e)}>
134134
Click me
@@ -138,17 +138,17 @@ class LoggingButton extends React.Component {
138138
}
139139
```
140140

141-
The problem with this syntax is that a different callback is created each time the `LoggingButton` renders. In most cases, this is fine. However, if this callback is passed as a prop to lower components, those components might do an extra re-rendering. We generally recommend binding in the constructor or using the class fields syntax, to avoid this sort of performance problem.
141+
El problema con esta sintaxis es que un callback diferente es creado cada vez que `LogginButton` es renderizado. En la mayoría de los casos, esto está bien. Sin embargo, si este callback se pasa como una propiedad a componentes más bajos, estos componentes podrían renderizarse nuevamente. Generalmente, recomendamos ligar en el constructor o usar la sintaxis de campos de clases, para evitar esta clase de problemas de rendimiento.
142142

143-
## Passing Arguments to Event Handlers {#passing-arguments-to-event-handlers}
143+
## Pasando Argumentos a Escuchadores de Eventos {#passing-arguments-to-event-handlers}
144144

145-
Inside a loop it is common to want to pass an extra parameter to an event handler. For example, if `id` is the row ID, either of the following would work:
145+
Dentro de un bucle es muy común querer pasar un parámetro extra a un manejador de eventos. Por ejemplo, si `id` es el ID de una fila, cualquiera de los códigos a continuación podría funcionar:
146146

147147
```js
148148
<button onClick={(e) => this.deleteRow(id, e)}>Delete Row</button>
149149
<button onClick={this.deleteRow.bind(this, id)}>Delete Row</button>
150150
```
151151

152-
The above two lines are equivalent, and use [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) and [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind) respectively.
152+
Las dos líneas anteriores son equivalentes, y utilizan [funciones flecha](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) y [`Function.prototype.bind`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_objects/Function/bind) respectivamente.
153153

154-
In both cases, the `e` argument representing the React event will be passed as a second argument after the ID. With an arrow function, we have to pass it explicitly, but with `bind` any further arguments are automatically forwarded.
154+
En ambos casos, el argumento `e` que representa el evento de React va a ser pasado como un segundo argumento después del ID. Con una función flecha, tenemos que pasarlo explícitamente, pero con `bind` cualquier argumento adicional es pasado automáticamente

0 commit comments

Comments
 (0)