This chapter covers
- Making the most of third-party hooks
- Accessing state in the URL with React Router’s useParams and useSearchParams hooks
- Switching to a new route with React Router’s useNavigate hook
- Efficiently fetching and caching data with React Query’s useQuery hook
- Updating data on the server with React Query’s useMutation hook
Chapter 9 introduced custom hooks as a way to extract functionality from components, making the functionality reusable and simplifying the components. Custom hooks provide a simple, readable way to access all kinds of functionality from a function component, whether that’s simple tasks like changing the document title or managing a state value with local storage, or increasingly complex tasks like fetching data or working with an application state manager. Many existing libraries have been quick to provide hooks to allow function components to make the most of the libraries’ features, and this chapter tries some out to improve the bookings example app.