React Hooks Tutorial - 12 - useReducer API

Veröffentlicht am: 19 August 2021
auf dem Kanal: 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


Auf dieser Seite können Sie das Online-Video React Hooks Tutorial - 12 - useReducer API mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer JAS ACADAMY 19 August 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 128 Mal angesehen und es wurde von 6 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!