Created
January 16, 2023 18:36
-
-
Save andycarrell/c7729318d2adb6e5cb494228abe313d1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useHTMLContainer() { | |
const container = useRef<HTMLDivElement | null>(null); | |
useEffect(() => { | |
const element = document.createElement('div'); | |
document.body.appendChild(element); | |
container.current = element; | |
return () => { | |
if (container.current) { | |
document.body.removeChild(container.current); | |
container.current = null; | |
} | |
}; | |
}, []); | |
return container.current; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment