What is a custom hook? Write a simple useToggle example.

What it tests: Whether you see hooks as stateful logic extraction. Outline: Define a use-prefixed function calling hooks; write useToggle with useState and callback; explain extraction vs duplication. Red flag: Helpers without hooks or missing use prefix.
What it tests: Whether you understand custom hooks as a mechanism for extracting and reusing stateful logic across components, not merely syntax. Answer outline: Define a custom hook as a JavaScript function starting with use that may call other Hooks; implement useToggle with useState and return a tuple of state and a stable toggle callback; explain when extraction beats duplication, such as sharing effects across unrelated components.
Read the original → react.dev
- #react
- #custom hooks
- #usestate
- #frontend
- #interview
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.