Skip to content

Instantly share code, notes, and snippets.

@dioscarey
Created April 14, 2020 19:09
Show Gist options
  • Save dioscarey/45c4de306c19d1eb77fe5fbc6b196a8c to your computer and use it in GitHub Desktop.
Save dioscarey/45c4de306c19d1eb77fe5fbc6b196a8c to your computer and use it in GitHub Desktop.
import React from 'react';
import BeforeUnloadComponent from 'react-beforeunload-component';
import MyModal from 'path/MyModal';
// React Hook
const Example = () => {
return (
<div>
<BeforeUnloadComponent
blockRoute={true}
modalComponentHandler={({handleModalLeave, handleModalCancel})=>{
return (
<MyModal
onClose={handleModalCancel}
onSubmit={handleModalLeave}
/>
)
}}
/>
<form id="myform"> ... </form>
<BeforeUnloadComponent/>
</div>
);
}
....
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment