This is a snippet of my code in a component. I’m trying to make a component whose height will change when the prop changes. How to fix the error? Property ‘style’ does not exist on type ‘MutableRefObject’
const bottom = useRef(null)
useEffect(() => {
active ?
bottom.style.maxHeight = '120px'
:
bottom.style.maxHeight = '0px'
}, [active])
return (
<div ref={bottom}></div>
)
>Solution :
const bottom = useRef<HTMLDivElement>(null)
useEffect(() => {
if (bottom.current) {
bottom.current.style.maxHeight = active ? '120px': '0'
}
}, [active])
- You need to specify the element type in your
useRef - You need to use
bottom.current - I’m not sure you can make assignments in a ternary