From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

useReducer introduction and syntax

useReducer introduction and syntax

Hello and welcome back, in this lesson we are going to start learning about the use reducer hook. We need the use reducer hook when we have a complex state to manage. When managing the state requires complex logic in function components. An alternative to that can be useState and especially when we have state logic involves multiple subvalues. By that I mean that the same thing we are able to do with useState hook as well but it makes things a lot complex. UseReducer hook allows us to handle that complexity in an easier way by the functioning that it provides. We should especially be looking for using the useReducer hook when our state logic involves multiple subvalues or different states in itself. For example, if your state is like specific statuses or different kind of stages where it can go through. For example, a record can be in pending status or it can be in in-progress status as well as it can be completed eventually. So during this state management, you have to manage the…

Contents