Building Your Own Hooks
In the previous chapter, we learned about the limitations and rules of Hooks. We also learned where to call Hooks, why the order matters, and naming conventions for Hooks.
In this chapter, we are going to learn how to create custom Hooks by extracting existing code from our components. We are also going to learn how to use custom Hooks and how Hooks can interact with each other. Finally, we are going to learn how to write tests for our custom Hooks.
At the end of this chapter, you will be able to create custom Hooks to encapsulate and re-use application logic, keeping your code clean and maintainable.
The following topics will be covered in this chapter:
- Creating a custom Theme Hook
- Creating a custom User Hook
- Creating custom API Hooks
- Creating a Debounced History State Hook
- Testing custom Hooks