React Hooks Tutorial - 12 - useReducer API

Publicado el: 19 agosto 2021
en el canal de: JAS ACADAMY
128
6

useReducer is used to store and update states, just like the useState Hook. It accepts a reducer function as its first parameter and the initial state as the second.

useReducer returns an array that holds the current state value and a dispatch function, to which you can pass an action and later invoke. This is similar to the pattern Redux uses but with a few differences.

For example, the useReducer function is tightly coupled to a specific reducer. We dispatch action objects to that reducer only, whereas in Redux, the dispatch function sends the action object to the store. At the time of dispatch, the components don’t need to know the reducer that will process the action.

For those who may be unfamiliar with Redux, we’ll explore this concept a bit further. There are three main building blocks in Redux:

A store — an immutable object that holds the applications state data
A reducer — a function that returns some state data, triggered by an action type
An action — an object that tells the reducer how to change the state. It must contain a type property, and it can contain an optional payload property


En esta página del sitio puede ver el video en línea React Hooks Tutorial - 12 - useReducer API de Duración hora minuto segunda en buena calidad , que subió el usuario JAS ACADAMY 19 agosto 2021, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 128 veces y le gustó 6 a los espectadores. Disfruta viendo!