Intermediate React Interview QuestionsIntermediateConcept
React · Question 42
Do two components using the same custom Hook share the same state?
Direct answer
No. A custom Hook shares reusable logic, but every component call receives its own Hook state unless that state is connected through a shared external source or context.
Calling the same custom Hook twice behaves like calling built-in Hooks twice: each call belongs to the component instance and has its own state slots.
- Shared automatically
- The Hook implementation and behavior
- Not shared automatically
- useState/useReducer state created by each Hook call
- Can be shared deliberately
- Context, an external store, URL state, server cache, or another shared data source