From the course: React: Design Patterns

Unlock this course with a free trial

Join today to access over 24,700 courses taught by industry experts.

What are custom hooks?

What are custom hooks? - React.js Tutorial

From the course: React: Design Patterns

What are custom hooks?

- Okay, the next React pattern that we're going to take a look at here is the pattern of Custom Hooks. So first of all, what are Custom Hooks? Custom Hooks are basically when instead of just using the basic hooks that React provides us with, such as useState and useEffect, we actually combine these hooks into our own new hooks. So what this might look like is, let's say that we want our component to have access to maybe something like products from the server. Well, we could either create the product state and actually load the products inside the component itself or we could create our own custom-used products hook that encapsulates this functionality and that would look something like this. We'll see a more in-depth example shortly. Now, once we've created a Custom Hook, in this case, once we've created our custom-used products hook or use user hook or use articles hook, whatever kind of resource or functionality we're trying to encapsulate in that hook, the way that we use it in…

Contents