Question 3 of 10Pro Only

What is a custom hook in React? Give an example of creating and using one.

Sample answer preview

A custom hook is a JavaScript function whose name starts with use and which calls other hooks. That is the whole definition; there is no special API. It is the mechanism React provides for extracting stateful logic so it can be reused across components.

custom hookuse prefixcompositionuseLocalStoragecleanuphigher-order component

Unlock the full answer

Get the complete model answer, key points, common pitfalls, and access to 9+ more Frontend Developer interview questions.

Upgrade to Pro

Starting at $19/month • Cancel anytime