Created
April 21, 2023 05:15
-
-
Save christiannaths/e34b25a664270a3da8defb7f9ddb8638 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 useElementSize(): [ | |
(el: HTMLElement | null) => void, | |
{ width?: number; height?: number } | |
] { | |
const [el, ref] = React.useState(null); | |
const width = React.useSyncExternalStore(noop, () => el?.offsetWidth); | |
const height = React.useSyncExternalStore(noop, () => el?.offsetHeight); | |
return [ref, { width, height }]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment