uidotdev / usehooks

A collection of modern, server-safe React hooks – from the ui.dev team
https://usehooks.com
MIT License
9.53k stars 499 forks source link

Type 'MutableRefObject<Element>' is not assignable to type 'LegacyRef<HTMLDialogElement> | undefined'. #250

Closed V-iktor closed 1 year ago

V-iktor commented 1 year ago

This example is not working in Typescript 5 with React 18

https://usehooks.com/useclickaway

kttmv commented 1 year ago

I was able to solve this issue by explicitly specifying the type of useClickAway like this:

const ref = useClickAway<HTMLDialogElement>(() => {
    ...
})

The same goes for other elements as well. If you want to reference, for example, a div, you should specify <HTMLDivElement>