elrumordelaluz / reactour

Tourist Guide into your React Components
https://react.tours
MIT License
3.85k stars 350 forks source link

beforeClose firing on mount #582

Open zakpucci opened 1 year ago

zakpucci commented 1 year ago

My assumption would be that the beforeClose event on the TourProvider would fire on mousedown on the close button. I'm seeing this event fire on mount if I call setIsOpen. Any know issues here? Am I missing something?

elrumordelaluz commented 1 year ago

Hi @zakpucci, thanks for open the Issue.

Sound weird. Mind creating a minimal reproduction in a sandbox in order to allow others to debug your use-case and try to find a solution? Thanks!

texonidas commented 1 year ago

I've run into this. You have your react in strict mode, which means all useEffects are run, then cleanup, then run again (basically a mount/remount). This is to ensure your side effects are clean. There is no way to disable it for portions of your application, so you will have to remove it entirely.

Sekky61 commented 6 months ago

Just ran into this. Would it be worth it to implement beforeClose differently?

Maybe add some behavior to setIsOpen(false)? The mounting of <Tour> is dependant on isOpen after all. The only problem I see there is if the whole TourProvider is unmounted.