Created
December 31, 2019 15:00
-
-
Save matijagalina/a910ffcafeeb12563231cbef5116c4fd to your computer and use it in GitHub Desktop.
Custom Prompt react-router
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ReactDOM from 'react-dom'; | |
import { BrowserRouter } from 'react-router-dom'; | |
// "react-router": "^5.1.2" | |
// "react-router-dom": "^5.1.2" | |
<BrowserRouter | |
getUserConfirmation={(message, callback) => ( | |
CustomPromptComponent(message, callback) | |
)} | |
> | |
... | |
</BrowserRouter> | |
// custom prompt message component | |
const CustomPromptComponent = (message, callback) => { | |
const container = document.createElement('div'); | |
container.setAttribute('custom-confirmation-navigation', ''); | |
document.body.appendChild(container); | |
const closeModal = (callbackState) => { | |
ReactDOM.unmountComponentAtNode(container); | |
callback(callbackState); | |
}; | |
ReactDOM.render( | |
<SomeModalComponent | |
closeModal={() => closeModal(false)} | |
closeCb={() => closeModal(true)} | |
> | |
{message} | |
</SomeModalComponent>, | |
container, | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment