Implement useClickOutside
Create a reusable pointer-outside hook with fresh callbacks, optional disabling, and complete listener cleanup.Description
Requirements
The solution exports the required useClickOutside API from the editable module.
Outside pointer works deterministically for the documented normal, boundary, and repeated-use scenarios.
Inside ignored works deterministically for the documented normal, boundary, and repeated-use scenarios.
Latest callback works deterministically for the documented normal, boundary, and repeated-use scenarios.
Disabled state works deterministically for the documented normal, boundary, and repeated-use scenarios.
Listener cleanup works deterministically for the documented normal, boundary, and repeated-use scenarios.
Rerender stability works deterministically for the documented normal, boundary, and repeated-use scenarios.
Fresh callback
Rerender with a new callback and click outside
Only the newest callback runs without reinstalling the listener
A callback ref separates current behavior from listener lifetime.
Constraints
Listen for pointerdown on documentIgnore events whose composed path includes the referenced nodeRemove every installed listener on cleanup
Hints
Hint 1
Store the latest callback in a ref so the document listener can stay stable.
Hint 2
Check disabled and node containment at event time.
Hint 3
Keep setup dependencies limited to values that truly require listener replacement.