Loading…
A short voice session: one question, one follow-up, then instant feedback — up to 5 minutes.
A custom hook is a function starting with use that calls other hooks; it shares stateful logic, but each component that calls it gets its own independent state.
Custom hooks extract repeated logic such as subscribing to window size, debouncing a value or managing a form field. Inside, they can use useState, useEffect and other hooks, and they return whatever the component needs. Two components calling useOnlineStatus() each get separate state; the hook shares code, not data. If you need shared data, combine the hook with context or an external store. Custom hooks must follow the rules of hooks and their names must start with use so tooling can check them.