9 Creating your own hooks
This chapter covers
- Extracting functionality into custom hooks
- Following the Rules of Hooks
- Consuming a context value with a custom hook
- Encapsulating data fetching with a custom hook
- Exploring further examples of custom hooks
React Hooks promise to simplify component code and to promote encapsulation, reusability, and maintainability. They let function components work closely with React to manage state and hook into life-cycle events for mounting, rendering, and unmounting. Function components with hooks collocate related code and remove the need to mix unrelated code within and across the separate life-cycle methods of class-based components.
Figure 9.1 contrasts the location of code in class-based and function-based ...
Get React Hooks in Action 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.