Summary
This chapter provided us with a more in-depth look at state management in a less ad hoc basis through useReducer
. useReducer
gives us a lot of helpful state management via using functionalities such as actions and payload. Our state modifications can be controlled and managed in a way that would be difficult to implement using only the useState
Hooks.
We also learned the proper way to clean up after ourselves to prevent the useEffect
hook from getting us into a bad scenario where we subscribe to events and listeners and then never unsubscribe from them. You can experiment with this in your activity by removing the cleanup from your useEffect
hook and seeing the result on your app.
In later chapters, we are going to dive even deeper into hooks, focusing on how to deal with shared context via Hooks to build great components with shared services.