Skip to content

Commit

Permalink
fix: typescript interface error
Browse files Browse the repository at this point in the history
  • Loading branch information
mvriu5 committed Aug 12, 2024
1 parent 102ad13 commit 40b1662
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "griller",
"license": "MIT",
"version": "1.0.16",
"version": "1.0.17",
"private": false,
"repository": {
"url": "https://github.com/mvriu5/griller"
Expand Down
31 changes: 16 additions & 15 deletions src/component/toastportal.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
import ReactDOM from 'react-dom';
import {createPortal} from 'react-dom';
import React, {ReactNode, useEffect, useState} from 'react';

interface ToastPortalProps {
children: ReactNode;
}

export const ToastPortal: React.FC<ToastPortalProps> = ({ children }) => {
const ToastPortal: React.FC<{children: ReactNode}> = ({ children }) => {
const [portalElement, setPortalElement] = useState<HTMLElement | null>(null);

useEffect(() => {
let element = document.getElementById('toast-portal-root');
if (!element) {
element = document.createElement('div');
element.id = 'toast-portal-root';
document.body.appendChild(element);
if (typeof window !== 'undefined') {
let element = document.getElementById('toast-portal-root');
if (!element) {
element = document.createElement('div');
element.id = 'toast-portal-root';
document.body.appendChild(element);
}
setPortalElement(element);
}
setPortalElement(element);

return () => {
if (element && element.parentNode) {
element.parentNode.removeChild(element);
if (portalElement && portalElement.parentNode) {
portalElement.parentNode.removeChild(portalElement);
}
};
}, []);

if (!portalElement) return null;

return ReactDOM.createPortal(children, portalElement);
};
return createPortal(children, portalElement);
};

export { ToastPortal };

0 comments on commit 40b1662

Please sign in to comment.