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 pitfalls and summary

Custom hook pitfalls and summary

Hello and welcome back, in this video we will discuss the common pitfalls while making our custom hooks. So the first one is not following hook naming conventions, we have already discussed this, so the hook name should always start with use. Second is using outside conditional or loops. There should be no outside intervention into your custom hooks, other than receiving the values for like initial states or initial values. You should even keep this flexible, like the use counter example, we were having a default value set to zero for the initial value. And if the user wants to provide the value, we can assign it to that value. But nothing from the outside code should dictate what's going to be happening inside your hook. The other pitfall can be sharing too much information or too little information. So you should receive the parameters inside your hook only what is needed, not any other useless thing or you should return back only the things that are needed for the outside world…

Contents