Closed jcalfee closed 6 years ago
Be aware that if the dialog is already close the method should probably not error. I would recommend to return true if you found the root node and closed it but false if the dialog was not found in the DOM.
function reactConfirmClose() {
const target = document.getElementById('react-confirm-alert');
if(!target) {
return false
}
const svg = document.getElementById('react-confirm-alert-firm-svg');
target.parentNode.removeChild(target);
svg.parentNode.removeChild(svg);
const root = document.body.children[0];
root.classList.remove('react-confirm-alert-blur');
return true
}
I believe this close logic is denying childrenElement their react life cycle events.
If I use an embedded QrReader (react-qr-reader) this close method leaves the camera on. If include the QrReader directly in render then the component gets removed via a higher level react condition, the camera does turn off.
@jcalfee Can you please create PR to solve this?
For the close logic it should have props willClose
prop type is a function to clear event listener or component that it wrapped.
Solve this in version 2 use option willUnmount
https://github.com/GA-MO/react-confirm-alert/blob/master/src/index.js#L37-L43
This would be useful in a react dumb component (without state) where
confirmAlert
was used to show the dialog.