fix: clear `LibraryUnit` DOM on unmount (#4084)

This commit is contained in:
David Luzar 2021-10-22 22:07:20 +02:00 committed by GitHub
parent ba35eb8f8c
commit 7dbd0c5e0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 3 deletions

View File

@ -34,6 +34,11 @@ export const LibraryUnit = ({
}) => {
const ref = useRef<HTMLDivElement | null>(null);
useEffect(() => {
const node = ref.current;
if (!node) {
return;
}
(async () => {
const elementsToRender = elements || pendingElements;
if (!elementsToRender) {
@ -47,10 +52,12 @@ export const LibraryUnit = ({
},
files,
);
if (ref.current) {
ref.current.innerHTML = svg.outerHTML;
}
node.innerHTML = svg.outerHTML;
})();
return () => {
node.innerHTML = "";
};
}, [elements, pendingElements, files]);
const [isHovered, setIsHovered] = useState(false);