Chapter 9: Use Custom Hooks to Reuse Logic
In the previous chapter, we learned how the useRef
hook is designed and how to use a ref for a state without updating the screen. In this chapter, we will gather all the hooks we have learned about so far and see how to create a custom hook for our own needs. We will introduce what a custom hook is and then write some custom hooks step by step, including useToggle
, useWindow
, useAsync
, useDebounced
, useClickOutside
, useCurrent
, and useProxy
.
We will cover the following topics in this chapter:
- Reviewing React hooks
useToggle
useWindow
useAsync
useDebounced
useClickOutside
useCurrent
useProxy
- Questions and answers