ElliotPenson / fractal.parts

❄️ build and view fractals
https://fractal.parts
MIT License
23 stars 1 forks source link

Show Confirmation Before Builder Exit #39

Closed ElliotPenson closed 5 years ago

ElliotPenson commented 5 years ago

Create a utility that adds a listener to the beforeunload event. This will cause a message to be shown to the user before they reload or exit the site.

window.addEventListener('beforeunload', event => {
  event.preventDefault();
  event.returnValue = '';
});

Call this utility in the componentDidMount method of Create. Remove the listener when the user publishes the fractal.