-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
@mantine/hooks useClickOutside ref typescript type is immutable #7259
Comments
I just came across this with |
Also, looks like this is a dupe of #7252 |
I cannot reproduce the issue on codesandbox https://codesandbox.io/p/sandbox/mantine-react-template-forked-nmnl8y |
https://codesandbox.io/p/sandbox/mantine-react-template-forked-pzk2y5 Needs to specify the element type to see the bug. Actual issue looks like: useClickOutside adds null to the ref type but LegacyRef on divs don't want the null. The reason MutableRefObject happens to fix this, for the curious, is because it's type directly accepts the generic without adding null interface MutableRefObject<T> {
current: T;
} whereas RefObject adds the null therefore inferring a non-null T for the generic interface RefObject<T> {
/**
* The current value of the ref.
*/
readonly current: T | null;
} |
MutableRefObject type is marked as deprecated in |
Removing that type makes it a |
Okay, you are welcome to submit a PR |
Dependencies check up
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?
Vite
In which browsers you can reproduce the issue?
None
Describe the bug
useClickOutside returns
Which is readonly. React's types don't allow you to pass this to
<div ref=
which is the canonical example given in the docs.If possible, include a link to a codesandbox with a minimal reproduction
No response
Possible fix
I believe this should be MutableRefObject instead
Self-service
The text was updated successfully, but these errors were encountered: