Fork me on GitHub
#re-frame
<
2023-05-25
>
Cássio Ribeiro Alves de Ávila14:05:47

Hello! What is the most idiomatic way of opening an alert when the user is trying to leave the page?

p-himik14:05:20

A custom effect.

Cássio Ribeiro Alves de Ávila14:05:41

and where I can find some documentation about doing that?

p-himik15:05:38

On the re-frame's website. :) The TOC and search should work just fine, and there are examples there as well.

Cássio Ribeiro Alves de Ávila15:05:03

I can't see a way to trigger the event the same way onbeforeunload would do it. I think I would have to just add the event there

p-himik15:05:52

So, something calls js/alert or something like that. That caller is an effect that you have to write. That effect will be used by an event handler, one that you also have to write. The event will be dispatched from somewhere, and that somewhere is probably a regular JS event handler for beforeunload.

p-himik15:05:35

If you don't consider opening that alert a part of your app's logic+state, then it doesn't need to be triggered by re-frame at all.

2