You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
El código actual de la aplicación se encuentra en el repositorio [https://github.com/fullstack-hy2020/hook-counter](https://github.com/fullstack-hy2020/hook-counter/tree/part6-1) en la rama <i>part6-1</i>.
494
494
495
-
### Using context for passing the state to components
495
+
### Usando context para pasar el estado a los componentes
496
496
497
-
If we want to split the application into several components, the value of the counter and the dispatch function used to manage it must also be passed to the other components. One solution would be to pass these as props in the usual way:
497
+
Si queremos dividir la aplicación en varios componentes, el valor del contador y la función de despacho utilizada para gestionarlo también deben pasarse a los otros componentes. Una solución sería pasar estos como props de la manera habitual:
498
498
499
499
```js
500
500
constDisplay= ({ counter }) => {
@@ -527,13 +527,13 @@ const App = () => {
527
527
}
528
528
```
529
529
530
-
The solution works, but is not optimal. If the component structure gets complicated, e.g. the dispatcher should be forwarded using props through many components to the components that need it, even though the components in between in the component tree do not need the dispatcher. This phenomenon is called <i>prop drilling</i>.
530
+
La solución funciona, pero no es óptima. Si la estructura de los componentes se complica, por ejemplo, el despachador debe transmitirse usando props a través de muchos componentes para llegar a los componentes que lo necesitan, aunque los componentes intermedios en el árbol de componentes no necesiten el despachador. Este fenómeno se llama <i>prop drilling</i>.
531
531
532
-
React's built-in [Context API](https://beta.reactjs.org/learn/passing-data-deeply-with-context)provides a solution for us. React's context is a kind of global state of the application, to which it is possible to give direct access to any component app.
532
+
La [API de contexto](https://beta.reactjs.org/learn/passing-data-deeply-with-context)integrada en React proporciona una solución para nosotros. El contexto de React es un tipo de estado global de la aplicación, al que se puede dar acceso directo a cualquier componente de la aplicación.
533
533
534
-
Let us now create a context in the application that stores the state management of the counter.
534
+
Vamos a crear ahora un contexto en la aplicación que almacene la gestión de estado del contador.
535
535
536
-
The context is created with React's hook [createContext](https://beta.reactjs.org/reference/react/createContext). Let's create a context in the file <i>CounterContext.js</i>:
536
+
El contexto se crea con el hook [createContext](https://beta.reactjs.org/reference/react/createContext) de React. Vamos a crear un contexto en el archivo <i>CounterContext.js</i>:
As can be seen, providing the context is done by wrapping the child components inside the <i>CounterContext.Provider</i> component and setting a suitable value for the context.
567
+
Como se puede ver, el proveedor de contexto se realiza envolviendo los componentes hijo dentro del componente <i>CounterContext.Provider</i> y estableciendo un valor adecuado para el contexto.
568
568
569
-
The context value is now set to be an array containing the value of the counter, and the <i>dispatch</i> function.
569
+
El valor del contexto ahora se establece en un arreglo que contiene el valor del contador y la función <i>dispatch</i>.
570
570
571
-
Other components now access the context using the [useContext](https://beta.reactjs.org/reference/react/useContext) hook:
571
+
Otros componentes ahora acceden al contexto utilizando el hook [useContext](https://beta.reactjs.org/reference/react/useContext):
0 commit comments