use-exit-intent
use-exit-intent copied to clipboard
FR: check cookie before triggering handleExitIntent
Hello,
currently, the cookie seems to be read once when the component is mounted: https://github.com/daltonmenezes/use-exit-intent/blob/main/packages/use-exit-intent/src/index.ts#L150.
This prevents unsubscribe logic to work, if it is triggered from another part of the application. However, I don't know if this is intentional. Our use case
- We have a nextjs application where
useExitIntent
is initialized in the root layout - We have a button near the footer where the user can willingly click to trigger the exit intend model dialog and subscribe
- When the user manually trigger the modal, we tigger
unsubscribe()
- Due to the cookie only been read during initial mount and not inside the handler callback, the modal triggers again in certain scenarios
In this use case the check for shouldNotTrigger.current
is not enough, as the exit-intent cookie won't be read again.
Any suggestions for solving this problem differently are welcome.