React ref types
Hey. I'm having some difficulty trying to set a type for a ref in React that can be applied to any HTML element.
13 Replies
My current implementation:
But TypeScript doesn't like that:
Type 'RefObject<HTMLElement>' is not assignable to type 'LegacyRef<HTMLDivElement> | undefined'
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I'm trying to create a custom hook that will work with pretty much any HTML element
hm, let me try that
no, it didn't help the situation, ts is still complaining
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah, but I'd like to be able to use this hook on another element if needed. Let's say a
span
or n ul
later onUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
Using any kind of defeats the purpose of ts here but thanks for the info. I'll keep experimenting 👀
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
hm that's a good idea
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
this method works well, thanks
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View