Hint
Custom hooks share logic, not state. Each component that calls a custom hook gets its own isolated state — this is a critical distinction from Context.
// Custom hooks share LOGIC, not STATE
function useCounter(initial = 0) {
let count = initial;
return {
increment() { count++; },
get() { return count; },
};
}
// Two components each call useCounter — independent state
const compA = useCounter(0);
const compB = useCounter(10);
compA.increment();
compA.increment();
compB.increment();
console.log(compA.get());
console.log(compB.get());
console.log(compA.get() === compB.get());2 11 false
Explanation: Each useCounter() call creates a new closure with its own count variable. compA and compB are completely independent.
Key Insight: Custom hooks share logic, not state. Each component that calls a custom hook gets its own isolated state — this is a critical distinction from Context.