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,600 courses taught by industry experts.
useReducer vs useState: Basic example
From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js
useReducer vs useState: Basic example
Hello and welcome back. Before starting on with the useReducerHook example, let's first go through how a useReducerHook is different or it can be compared with useStateHook. We'll keep it a scenario and see if the useStateHook and the useReducerHook is viable to that scenario or not. So when you have simple state like 1 or 2 values, the useState hook is and should be preferred and using the useReducer hook will be an overkill, but it can do this. If you have a complex state object, which requires multiple state transitions, then Using the useState hook, you can achieve it, but it is going to become messy, whereas the useReducer is preferred choice. When your state depends on the previous state values, it's hard to manage using the useState, but it becomes very easy using the useReducer. and when you have multiple actions which are going to modify the state value for example moving the record to pending to in progress or from in progress to in review so you can see that there are…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Introduction to hooks wrapper hell5m 56s
-
(Locked)
Complex lifecycle logic5m 11s
-
(Locked)
This keyword confusion3m 55s
-
(Locked)
useState hook6m 3s
-
(Locked)
Lazy initialization3m 58s
-
(Locked)
Managing objects8m 33s
-
(Locked)
Managing arrays: Summary4m 7s
-
(Locked)
useEffect hook: Introduction4m 6s
-
(Locked)
useEffect problem9m 24s
-
(Locked)
useEffect API calling5m 50s
-
(Locked)
useEffect dependency arrays10m 34s
-
(Locked)
useEffect cleanup function and summary5m 18s
-
(Locked)
useContext introduction3m 50s
-
(Locked)
Theme context: Implementing the provider9m 36s
-
(Locked)
Theme switcher and header component6m 26s
-
(Locked)
Use cases: Summary4m 52s
-
(Locked)
useRef introduction: DOM elements6m 47s
-
(Locked)
useRef timer example: Mutable values3m 55s
-
(Locked)
useRef common cases and comparison with useState2m 26s
-
(Locked)
useReducer introduction and syntax4m 46s
-
(Locked)
useReducer vs useState: Basic example5m 59s
-
(Locked)
useReducer status manager example14m 50s
-
(Locked)
useReducer vs Redux: Summary4m 39s
-
(Locked)
useMemo introduction6m 38s
-
(Locked)
useMemo real-world example13m 58s
-
(Locked)
useMemo dos and don'ts: Summary6m 13s
-
(Locked)
useCallback introduction3m 41s
-
(Locked)
useCallback example and understanding10m 41s
-
(Locked)
useCallback summary and pitfalls3m 17s
-
(Locked)
useImperativeHandle introduction4m 8s
-
(Locked)
useImperative example and uses5m 25s
-
(Locked)
useImperative common use case and summary4m 14s
-
(Locked)
Custom hook introduction4m 54s
-
(Locked)
Custom hook example and usage4m 55s
-
(Locked)
Custom hook design principles4m 9s
-
(Locked)
Custom hook pitfalls and summary4m 9s
-
(Locked)
-
-
-
-