Skip to content

Commit 7bcb62d

Browse files
Merge pull request #19 from ElRodrigote/conditional-rendering-translation
Conditional Rendering translation
2 parents 8ebf5de + d3e9f9d commit 7bcb62d

File tree

1 file changed

+33
-39
lines changed

1 file changed

+33
-39
lines changed

content/docs/conditional-rendering.md

Lines changed: 33 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
---
22
id: conditional-rendering
3-
title: Conditional Rendering
3+
title: Renderizado condicional
44
permalink: docs/conditional-rendering.html
55
prev: handling-events.html
66
next: lists-and-keys.html
77
redirect_from:
88
- "tips/false-in-jsx.html"
99
---
1010

11-
In React, you can create distinct components that encapsulate behavior you need. Then, you can render only some of them, depending on the state of your application.
11+
En React, puedes crear distintos componentes que encapsulan el comportamiento que necesitas. Entonces, puedes renderizar solamente algunos de ellos, dependiendo del estado de tu aplicación.
1212

13-
Conditional rendering in React works the same way conditions work in JavaScript. Use JavaScript operators like [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) or the [conditional operator](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator) to create elements representing the current state, and let React update the UI to match them.
13+
El renderizado condicional en React funciona de la misma forma que lo hacen las condiciones en JavaScript. Usa operadores de JavaScript como [`if`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/if...else) o el [operador condicional](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Operadores/Conditional_Operator) para crear elementos representando el estado actual, y deja que React actualice la UI para emparejarlos.
1414

15-
Consider these two components:
15+
Considera estos dos componentes:
1616

1717
```js
1818
function UserGreeting(props) {
@@ -24,7 +24,7 @@ function GuestGreeting(props) {
2424
}
2525
```
2626

27-
We'll create a `Greeting` component that displays either of these components depending on whether a user is logged in:
27+
Vamos a crear un componente `Greeting` que muestra cualquiera de estos componentes dependiendo si el usuario ha iniciado sesión:
2828

2929
```javascript{3-7,11,12}
3030
function Greeting(props) {
@@ -36,21 +36,21 @@ function Greeting(props) {
3636
}
3737
3838
ReactDOM.render(
39-
// Try changing to isLoggedIn={true}:
39+
// Intentar cambiando isLoggedIn={true}:
4040
<Greeting isLoggedIn={false} />,
4141
document.getElementById('root')
4242
);
4343
```
4444

45-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
45+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/ZpVxNq?editors=0011)
4646

47-
This example renders a different greeting depending on the value of `isLoggedIn` prop.
47+
Este ejemplo renderiza un saludo diferente según el valor de la prop `isLoggedIn`.
4848

49-
### Element Variables
49+
### Variables de elementos
5050

51-
You can use variables to store elements. This can help you conditionally render a part of the component while the rest of the output doesn't change.
51+
Puedes usar variables para almacenar elementos. Esto puede ayudarte para renderizar condicionalmente una parte del componente mientras el resto del resultado no cambia.
5252

53-
Consider these two new components representing Logout and Login buttons:
53+
Considera estos dos componentes nuevos que representan botones de cierre e inicio de sesión:
5454

5555
```js
5656
function LoginButton(props) {
@@ -70,9 +70,9 @@ function LogoutButton(props) {
7070
}
7171
```
7272

73-
In the example below, we will create a [stateful component](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) called `LoginControl`.
73+
En el siguiente ejemplo, crearemos un [componente con estado](/docs/state-and-lifecycle.html#adding-local-state-to-a-class) llamado `LoginControl`.
7474

75-
It will render either `<LoginButton />` or `<LogoutButton />` depending on its current state. It will also render a `<Greeting />` from the previous example:
75+
El componente va a renderizar `<LoginButton />` o `<LogoutButton />` dependiendo de su estado actual. También va a renderizar un `<Greeting />` del ejemplo anterior:
7676

7777
```javascript{20-25,29,30}
7878
class LoginControl extends React.Component {
@@ -82,25 +82,20 @@ class LoginControl extends React.Component {
8282
this.handleLogoutClick = this.handleLogoutClick.bind(this);
8383
this.state = {isLoggedIn: false};
8484
}
85-
8685
handleLoginClick() {
8786
this.setState({isLoggedIn: true});
8887
}
89-
9088
handleLogoutClick() {
9189
this.setState({isLoggedIn: false});
9290
}
93-
9491
render() {
9592
const isLoggedIn = this.state.isLoggedIn;
9693
let button;
97-
9894
if (isLoggedIn) {
9995
button = <LogoutButton onClick={this.handleLogoutClick} />;
10096
} else {
10197
button = <LoginButton onClick={this.handleLoginClick} />;
10298
}
103-
10499
return (
105100
<div>
106101
<Greeting isLoggedIn={isLoggedIn} />
@@ -116,13 +111,13 @@ ReactDOM.render(
116111
);
117112
```
118113

119-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
114+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/QKzAgB?editors=0010)
120115

121-
While declaring a variable and using an `if` statement is a fine way to conditionally render a component, sometimes you might want to use a shorter syntax. There are a few ways to inline conditions in JSX, explained below.
116+
Si bien declarar una variable y usar una sentencia `if` es una buena forma de renderizar condicionalmente un componente, a veces podrías querer usar una sintaxis más corta. Hay algunas formas de hacer condiciones en una línea en JSX, explicadas a continuación.
122117

123-
### Inline If with Logical && Operator
118+
### If en una línea con operador lógico &&
124119

125-
You may [embed any expressions in JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) by wrapping them in curly braces. This includes the JavaScript logical `&&` operator. It can be handy for conditionally including an element:
120+
Puedes [embeber cualquier expresión en JSX](/docs/introducing-jsx.html#embedding-expressions-in-jsx) envolviéndola en llaves. Esto incluye al operador lógico `&&` de JavaScript. Puede ser útil para incluir condicionalmente un elemento:
126121

127122
```js{6-10}
128123
function Mailbox(props) {
@@ -146,17 +141,17 @@ ReactDOM.render(
146141
);
147142
```
148143

149-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
144+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/ozJddz?editors=0010)
150145

151-
It works because in JavaScript, `true && expression` always evaluates to `expression`, and `false && expression` always evaluates to `false`.
146+
Esto funciona porque en JavaScript, `true && expresión` siempre evalúa a `expresión`, y `false && expresión` siempre evalúa a `false`.
152147

153-
Therefore, if the condition is `true`, the element right after `&&` will appear in the output. If it is `false`, React will ignore and skip it.
148+
Por eso, si la condición es `true`, el elemento justo después de `&&` aparecerá en el resultado. Si es `false`, React lo ignorará.
154149

155-
### Inline If-Else with Conditional Operator
150+
### If-Else en una línea con operador condicional
156151

157-
Another method for conditionally rendering elements inline is to use the JavaScript conditional operator [`condition ? true : false`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Conditional_Operator).
152+
Otro método para el renderizado condicional de elementos en una línea es usar el operador condicional [`condición ? true : false`](https://developer.mozilla.org/es/docs/Web/JavaScript/Referencia/Operadores/Conditional_Operator) de JavaScript.
158153

159-
In the example below, we use it to conditionally render a small block of text.
154+
En el siguiente ejemplo, lo usaremos para renderizar de forma condicional un pequeño bloque de texto.
160155

161156
```javascript{5}
162157
render() {
@@ -169,7 +164,7 @@ render() {
169164
}
170165
```
171166

172-
It can also be used for larger expressions although it is less obvious what's going on:
167+
También puede usarse para expresiones más grandes, aunque es menos obvio lo que está pasando:
173168

174169
```js{5,7,9}
175170
render() {
@@ -179,27 +174,26 @@ render() {
179174
{isLoggedIn ? (
180175
<LogoutButton onClick={this.handleLogoutClick} />
181176
) : (
182-
<LoginButton onClick={this.handleLoginClick} />
177+
<LoginButton onClick={this.handleLoginClick} />
183178
)}
184179
</div>
185180
);
186181
}
187182
```
188183

189-
Just like in JavaScript, it is up to you to choose an appropriate style based on what you and your team consider more readable. Also remember that whenever conditions become too complex, it might be a good time to [extract a component](/docs/components-and-props.html#extracting-components).
184+
Al igual que en JavaScript, depende de ti elegir un estilo apropiado en base a lo que tu y tu equipo consideran más legible. Recuerda también que cuando las condiciones se vuelven demasiado complejas, puede ser un buen momento para [extraer un componente](/docs/components-and-props.html#extracting-components).
190185

191-
### Preventing Component from Rendering
186+
### Evitar que el componente se renderice
192187

193-
In rare cases you might want a component to hide itself even though it was rendered by another component. To do this return `null` instead of its render output.
188+
En casos excepcionales, es posible que desees que un componente se oculte a sí mismo aunque haya sido renderizado por otro componente. Para hacer esto, devuelve `null` en lugar del resultado de renderizado.
194189

195-
In the example below, the `<WarningBanner />` is rendered depending on the value of the prop called `warn`. If the value of the prop is `false`, then the component does not render:
190+
En el siguiente ejemplo, el `<WarningBanner />` se renderiza dependiendo del valor de la prop llamada `warn`. Si el valor de la prop es `false`, entonces el componente no se renderiza:
196191

197192
```javascript{2-4,29}
198193
function WarningBanner(props) {
199194
if (!props.warn) {
200195
return null;
201196
}
202-
203197
return (
204198
<div className="warning">
205199
Warning!
@@ -213,13 +207,11 @@ class Page extends React.Component {
213207
this.state = {showWarning: true};
214208
this.handleToggleClick = this.handleToggleClick.bind(this);
215209
}
216-
217210
handleToggleClick() {
218211
this.setState(state => ({
219212
showWarning: !state.showWarning
220213
}));
221214
}
222-
223215
render() {
224216
return (
225217
<div>
@@ -238,6 +230,8 @@ ReactDOM.render(
238230
);
239231
```
240232

241-
[**Try it on CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
233+
[**Pruébalo en CodePen**](https://codepen.io/gaearon/pen/Xjoqwm?editors=0010)
234+
235+
El devolver `null` desde el método `render` de un componente no influye en la activación de los métodos del ciclo de vida del componente. Por ejemplo `componentDidUpdate` seguirá siendo llamado.
236+
242237

243-
Returning `null` from a component's `render` method does not affect the firing of the component's lifecycle methods. For instance `componentDidUpdate` will still be called.

0 commit comments

Comments
 (0)