This video is available to students only
- The newline Guide to Modernizing an Enterprise React App
- Create Custom Hooks for the App
Our First Custom Hook: useDepartments
We'll write our first custom hook to fetch department info for our application in one centralized place.
This page is a preview of The newline Guide to Modernizing an Enterprise React App
- Custom hooks may sound intimidating at first, but useDepartments should change your mind
- We make duplicate calls to the department API
- Create a new hooks folder
- Make a new useDepartments.js file
- Review the code currently fetching departments
- Compose the hook
- Move the fetchDepartments function into the hook
- Remove setLoading and return departments and errors from the hook
Contents