Skip to content

Commit 5364bdc

Browse files
Fixing hooks-reference
1 parent b6a753b commit 5364bdc

File tree

1 file changed

+1
-47
lines changed

1 file changed

+1
-47
lines changed

content/docs/hooks-reference.md

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,7 @@ prev: hooks-custom.html
66
next: hooks-faq.html
77
---
88

9-
<<<<<<< HEAD
10-
Los *Hooks* son una próxima característica que te permite usar el estado y otras características de React sin escribir una clase. Están actualmente en React v16.8.0-alpha.1.
11-
=======
129
*Hooks* are a new addition in React 16.8. They let you use state and other React features without writing a class.
13-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
1410

1511
Esta página describe las API para los Hooks incorporados en React.
1612

@@ -83,11 +79,7 @@ Los botones "+" y "-" usan la forma funcional, porque el valor actualizado se ba
8379
>
8480
> Otra opción es `useReducer`, que es más adecuada para administrar objetos de estado que contienen múltiples subvalores.
8581
86-
<<<<<<< HEAD
8782
#### Inicialización gradual
88-
=======
89-
#### Lazy initial state
90-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
9183
9284
El argumento `initialState` es el estado utilizado durante el render inicial. En renders posteriores, se ignora. Si el estado inicial es el resultado de un cálculo costoso, puede proporcionar una función en su lugar, que se ejecutará solo en el render inicial:
9385
@@ -190,13 +182,9 @@ const [state, dispatch] = useReducer(reducer, initialArg, init);
190182

191183
Una alternativa a [`useState`](#usestate). Acepta un reducer de tipo `(state, action) => newState` y devuelve el estado actual emparejado con un método` dispatch`. (Si está familiarizado con Redux, ya sabe cómo funciona).
192184

193-
<<<<<<< HEAD
194-
Aquí está el ejemplo de contador de la sección [`useState`] (# usestate), reescrito para usar un reducer:
195-
=======
196185
`useReducer` is usually preferable to `useState` when you have complex state logic that involves multiple sub-values or when the next state depends on the previous one. `useReducer` also lets you optimize performance for components that trigger deep updates because [you can pass `dispatch` down instead of callbacks](/docs/hooks-faq.html#how-to-avoid-passing-callbacks-down).
197186

198187
Here's the counter example from the [`useState`](#usestate) section, rewritten to use a reducer:
199-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
200188

201189
```js
202190
const initialState = {count: 0};
@@ -208,13 +196,7 @@ function reducer(state, action) {
208196
case 'decrement':
209197
return {count: state.count - 1};
210198
default:
211-
<<<<<<< HEAD
212-
// Un reducer siempre debe devolver un estado válido.
213-
// Alternativamente, puede lanzar un error si se envía una acción no válida.
214-
return state;
215-
=======
216199
throw new Error();
217-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
218200
}
219201
}
220202

@@ -230,11 +212,6 @@ function Counter({initialCount}) {
230212
}
231213
```
232214

233-
<<<<<<< HEAD
234-
#### Inicialización diferida
235-
236-
`useReducer` acepta un tercer argumento opcional, `initialAction`. Si se proporciona, la acción inicial se aplica durante el render inicial. Esto es útil para calcular un estado inicial que incluye valores pasados a través de props:
237-
=======
238215
#### Specifying the initial state
239216

240217
There’s two different ways to initialize `useReducer` state. You may choose either one depending on the use case. The simplest way to pass the initial state as a second argument:
@@ -253,7 +230,6 @@ There’s two different ways to initialize `useReducer` state. You may choose ei
253230
#### Lazy initialization
254231

255232
You can also create the initial state lazily. To do this, you can pass an `init` function as the third argument. The initial state will be set to `init(initialArg)`.
256-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
257233

258234
It lets you extract the logic for calculating the initial state outside the reducer. This is also handy for resetting the state later in response to an action:
259235

@@ -409,25 +385,16 @@ useDebugValue(value)
409385

410386
`useDebugValue` puede usarse para mostrar una etiqueta para Hooks personalizados en React DevTools.
411387

412-
<<<<<<< HEAD
413-
Por ejemplo, considere el Hook personalizado `useFriendStatus` descrito en ["Construyendo sus propios Hooks"](/docs/hooks-custom.html):
414-
=======
415-
For example, consider the `useFriendStatus` custom Hook described in ["Building Your Own Hooks"](/docs/hooks-custom.html):
416-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
388+
Por ejemplo, considera el Hook personalizado `useFriendStatus` descrito en ["Construyendo sus propios Hooks"](/docs/hooks-custom.html):
417389

418390
```js{6-8}
419391
function useFriendStatus(friendID) {
420392
const [isOnline, setIsOnline] = useState(null);
421393
422394
// ...
423395
424-
<<<<<<< HEAD
425396
// Mostrar una etiqueta en DevTools junto a este Hook
426397
// por ejemplo: "FriendStatus: Online"
427-
=======
428-
// Show a label in DevTools next to this Hook
429-
// e.g. "FriendStatus: Online"
430-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
431398
useDebugValue(isOnline ? 'Online' : 'Offline');
432399
433400
return isOnline;
@@ -436,28 +403,15 @@ function useFriendStatus(friendID) {
436403

437404
> Consejo
438405
>
439-
<<<<<<< HEAD
440406
> No recomendamos agregar valores de depuración a cada Hook personalizado. Es más valioso para los Hooks personalizados que forman parte de las bibliotecas compartidas.
441-
=======
442-
> We don't recommend adding debug values to every custom Hook. It's most valuable for custom Hooks that are part of shared libraries.
443-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
444407
445408
#### Aplazar el formato de los valores de depuración
446409

447-
<<<<<<< HEAD
448410
En algunos casos, formatear un valor para mostrar puede ser una operación costosa. También es innecesario a menos que un Hook sea realmente inspeccionado.
449411

450412
Por esta razón, `useDebugValue` acepta una función de formato como un segundo parámetro opcional. Esta función solo se llama si se inspeccionan los Hooks. Recibe el valor de depuración como parámetro y debe devolver un valor de visualización formateado.
451413

452414
Por ejemplo, un Hook personalizado que devolvió un valor de `Date` podría evitar llamar a la función `toDateString` innecesariamente al pasar el siguiente formateador:
453-
=======
454-
In some cases formatting a value for display might be an expensive operation. It's also unnecessary unless a Hook is actually inspected.
455-
456-
For this reason `useDebugValue` accepts a formatting function as an optional second parameter. This function is only called if the Hooks are inspected. It receives the debug value as a parameter and should return a formatted display value.
457-
458-
For example a custom Hook that returned a `Date` value could avoid calling the `toDateString` function unnecessarily by passing the following formatter:
459-
460-
>>>>>>> 98c1d22fbef2638cafb03b07e0eabe2a6186fca8
461415
```js
462416
useDebugValue(date, date => date.toDateString());
463417
```

0 commit comments

Comments
 (0)