use-exit-intent icon indicating copy to clipboard operation
use-exit-intent copied to clipboard

FR: check cookie before triggering handleExitIntent

Open patshologram opened this issue 1 year ago • 0 comments

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.

patshologram avatar Aug 17 '23 12:08 patshologram