From the course: Build Modern Web Apps with React, Hooks, State Management, and APIs Using Vite or Next.js

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Custom hook introduction

Custom hook introduction

Hello and welcome to lesson number 10. In this lesson, we'll understand what custom hooks are and how we can do the reusable logic while building them. Custom hooks are like a simple JavaScript function that start with a use keyword and allow you to reuse stateful logic across the components. I want you to remember and think of the functional way of doing programming. If you remember while coding in JavaScript, you should remember that at times you have a single function or the main function which has become fatty and you have a lot of logic inside that function. So when told to make it look optimized and some reusability inside the code, we usually do multiple functions and distribute the logic that is needed for the single each function. For example, you have a function to calculate something. Then all the calculation logic can go to that one function and inside your main function, you can just call the calculate function. And then you have a print logic and then you can change that…

Contents