uidotdev / usehooks

A collection of modern, server-safe React hooks – from the ui.dev team

Home Page:https://usehooks.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

V-iktor opened this issue · comments

This example is not working in Typescript 5 with React 18

https://usehooks.com/useclickaway

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>