JSFiddle - React, Tailwind, and code Playground

HTML

<label>
    <input type="checkbox" onchange="shouldNotWarnBeforeUnload=this.checked">
    Should a warning not show show up?
</label>
If checked, no dialog appears. <a href='.'>Refresh</a>.

JavaScript

var shouldNotWarnBeforeUnload = false;

window.onbeforeunload = function() { 
    if (!shouldNotWarnBeforeUnload) {
        return ('Are you sure you want to leave the page?');
    }
};