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

Reviewing React hooks

We have seen quite a few hooks provided by React. Let's take a moment ...

Get Designing React Hooks the Right Way now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.