Skip to content

Commit

Permalink
fix: modal wrapper auto destroy (#258)
Browse files Browse the repository at this point in the history
* fix: modal wrapper auto destroy

* fix: modal wrapper auto destroy
  • Loading branch information
mizy authored May 12, 2023
1 parent 4fb3203 commit 9189f84
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/components/ModalWrapper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import React from 'react';
import ReactDOM from 'react-dom';

function ModalWrapper<T>(Component: React.FC<T>) {

const container = document.createElement('div');
const hide = () => {
setTimeout(() => {
ReactDOM.unmountComponentAtNode(container);
window.removeEventListener("popstate",hide);
}, 200);
};

const show = (props: T) => {
ReactDOM.render(<Component visible {...props} hide={hide} />, container);
window.addEventListener("popstate",hide);
};

return {
Expand Down

0 comments on commit 9189f84

Please sign in to comment.