Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useHover, useMouse, other hooks have a type error for refs #7252

Open
1 of 2 tasks
QuinnStraus opened this issue Dec 12, 2024 · 5 comments
Open
1 of 2 tasks

useHover, useMouse, other hooks have a type error for refs #7252

QuinnStraus opened this issue Dec 12, 2024 · 5 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@QuinnStraus
Copy link
Contributor

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.15.1

What package has an issue?

@mantine/hooks

What framework do you use?

Next.js

In which browsers you can reproduce the issue?

Chrome

Describe the bug

The type signature for the ref objects returned from the hooks is RefObject<T | null> rather than RefObject, creating the following type error when the refs are passed into the ref prop of an html element:
Type 'RefObject<HTMLDivElement | null>' is not assignable to type 'RefObject<HTMLDivElement>'.
The hooks seem to still work as expected.

If possible, include a link to a codesandbox with a minimal reproduction

https://codesandbox.io/p/sandbox/mantine-react-template-forked-lnp22m

Possible fix

Return the hook type signature to RefObject.

Self-service

  • I would be willing to implement a fix for this issue
@QuinnStraus
Copy link
Contributor Author

Update: this seems to be an issue with react 19 changing the return type of useRef and the ref prop on html elements, since I had upgraded my project to mantine 7.15 but not react 19 yet. Codesandbox seems to also not have been using the react 19 types, causing the issue to reproduce there.

@jonavila
Copy link
Contributor

Same, issue for me with existing useElementSize, useHover and a few others.

@rtivital
Copy link
Member

I cannot reproduce the issue https://codesandbox.io/p/sandbox/mantine-react-template-forked-m23r4p
Please provide a sandbox with a minimal reproduction

@rtivital rtivital added the Needs reproduction Issues without reproduction, closed within a week if the reproduction is not provided label Dec 15, 2024
@jonavila
Copy link
Contributor

@rtivital The codesanbox link posted with the ticket shows the TS error: https://codesandbox.io/p/sandbox/mantine-react-template-forked-lnp22m

image

rtivital added a commit that referenced this issue Dec 16, 2024
@rtivital
Copy link
Member

Thanks, I've found the issue with some hooks, fixed it, will be available with the next patch.

@rtivital rtivital added Fixed patch Completed issues that will be published with next patch (1.0.X) and removed Needs reproduction Issues without reproduction, closed within a week if the reproduction is not provided labels Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

3 participants