From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Unlock the full course today
Join today to access over 24,800 courses taught by industry experts.
Handle complex logic with useReducer
From the course: Building Production-Ready React Apps: Setup to Deployment with Firebase
Handle complex logic with useReducer
- [Instructor] When your app starts to grow, state management needs to be handled very effectively and separately. For that you can use another hook, useReducer, which is a good alternative to useState. So useReducer accepts two entries, first, the function reducer, and another one optional, which is the initialState. Then it returns an array with the current state and the dispatch method that we use to send actions to a function reducer, which is then in charge of returning a new state. And with the new state, we can then update the UI of the components. So let's go back to the source code and see how we can move the business logic and the state management in a separate location. For that, we're going to use useReducer that we're going to add to the scope of this component. Then we're going to write an instance of useReducer that takes two entries. So first the function reducer and the initial state. So we're going to…
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
-
-
-
-
-
Introduction to Hooks API Reference2m 52s
-
(Locked)
Learn event handling and updating the state4m 12s
-
(Locked)
Handle conditional rendering3m 47s
-
(Locked)
Work with forms4m 1s
-
(Locked)
Submit the form and apply side effects: useEffect5m 32s
-
(Locked)
Validate and submit forms: useMemo6m 11s
-
(Locked)
Handle complex logic with useReducer5m 34s
-
(Locked)
Create and dispatch actions4m 37s
-
(Locked)
Compose and update the UI6m 1s
-
-
-
-
-
-
-
-
-
-