'Unable to get height from useRef
I am trying to get the height of the div from my project. But when I run this I get Property 'offsetHeight' does not exist on type 'never'
This is my code:
const customMenuRef = useRef(null);
useEffect(() => {
if (customMenuRef) {
console.log(customMenuRef.current?.offsetHeight);
}
}, [customMenuRef]);
return (
<div ref={customMenuRef}>
test
</div>
);
If I simply run console.log(customMenuRef.Current) I do get a current object with all the info I need, but I simply can't reach them.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
