질문
Material UI로 구현한 Dialog component를 overlay-kit으로 제어하고 있습니다.
Dialog를 unmount하기 위해서 overlay-kit의 unmount 함수를 사용했지만, Dialog를 열면 여전히 닫힌 Dialog의 count가 함께 console에 출력됩니다.
이 현상은 Dialog component가 완전히 unmount되지 않았다는 것을 의미한다고 생각합니다.
예시 코드
Code Sandbox
import { useEffect, useState } from "react";
import { Button, Dialog, DialogContent } from "@mui/material";
import { overlay } from "overlay-kit";
export default function App() {
const [isOpen, setIsOpen] = useState(false);
const [count, setCount] = useState(0);
const openDialogA = () => {
setCount((prev) => prev + 1);
setIsOpen(true);
};
const closeDialogA = () => setIsOpen(false);
return (
<div style={{ display: "flex", gap: 10 }}>
<Button onClick={openDialogA} variant="contained">
Dialog A Open
</Button>
<DialogA isOpen={isOpen} onClose={closeDialogA} count={count} />
<Button
variant="contained"
onClick={() => {
setCount((prev) => prev + 1);
overlay.open(({ isOpen, close, unmount }) => (
<DialogB
isOpen={isOpen}
onClose={close}
onExit={unmount}
count={count}
/>
));
}}
>
Dialog B Open
</Button>
</div>
);
}
interface DialogAProps {
isOpen: boolean;
onClose: () => void;
count: number;
}
// State로 제어
const DialogA = ({ isOpen, onClose, count }: DialogAProps) => {
console.log("Dialog A Count: ", count);
return (
<Dialog open={isOpen} onClose={onClose}>
<DialogContent>Dialog A</DialogContent>
</Dialog>
);
};
interface DialogBProps {
isOpen: boolean;
onClose: () => void;
onExit: () => void;
count: number;
}
// overlay-kit으로 제어
const DialogB = ({ isOpen, onClose, onExit, count }: DialogBProps) => {
console.log("Dialog B Count: ", count);
useEffect(() => {
return () => onExit();
}, []);
return (
<Dialog open={isOpen} onClose={onClose}>
<DialogContent>Dialog B</DialogContent>
</Dialog>
);
};
기대 결과
Dialog를 open할 때, 이전에 닫힌 Dialog의 count가 console에 출력되지 않아야 합니다.
실행 결과
Dialog를 open할 때, 이미 닫힌 Dialog의 count도 console에 함께 출력됩니다.
질문
Material UI로 구현한 Dialog component를 overlay-kit으로 제어하고 있습니다.
Dialog를 unmount하기 위해서 overlay-kit의 unmount 함수를 사용했지만, Dialog를 열면 여전히 닫힌 Dialog의 count가 함께 console에 출력됩니다.
이 현상은 Dialog component가 완전히 unmount되지 않았다는 것을 의미한다고 생각합니다.
예시 코드
Code Sandbox
기대 결과
Dialog를 open할 때, 이전에 닫힌 Dialog의 count가 console에 출력되지 않아야 합니다.
실행 결과
Dialog를 open할 때, 이미 닫힌 Dialog의 count도 console에 함께 출력됩니다.