Usually when I use React + Typescript and I have to work with refs I usually use this check:
const ref = useRef<HTMLDivElement>(null) ... if(ref && ref.current)
But recently, I’m receiving this error:
Property 'current' does not exist on type '((instance: HTMLDivElement | null) => void) | RefObject<HTMLDivElement>'. Property 'current' does not exist on type '(instance: HTMLDivElement | null) => void'.ts(2339)
Any ideas on what this error means? To solve the issue, as a workaround, I’m adding a third check:
if(ref && "current" in ref && ref.current)
But this looks pretty bad, mainly when you have to work with multiple refs at once.
Thanks for your help.