-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
[useMeasure] Ability to track a custom Ref #1227
Comments
+1 on this. I already have my |
I just ran in the same issue, would also love this! |
Hey! How do you think, should we pass a real
or
I am asking because |
Looks like this proposal contains breaking backward compatibility. Should new PR implement it like that?
or
|
@ashubham @streamich What do you think? |
what if you create and return a ref if no ref was passed in? |
@joeshub Great idea for the JavaScript but how TypeScript types should look like in this case? |
+1 for supporting a passed ref |
Could be something like that ?
If the You could use the hook like that :
@dmitrij-borchuk Another solution could be to have two distinct types for the hook :
This would keep backward compatibility, without having a too weird interface. But this will add more complexity in the code, so I'm not sure it's worth it. What do you think ? |
@PoOw Thank you for the idea, you are awesome! I totally forget that TypeScript has Overloads (https://www.typescriptlang.org/docs/handbook/functions.html#overloads). I will work around that solution |
+1 |
Hi all! @react-hookz/web, the new library by one of For those interested, there's an official migration guide for migrating from react-use to @react-hookz/web. Hope this helps! |
is there any update on this? Passing ref from useMeasure as a ref gives typescript error as it is not a accepted ref object: |
Hi @terragady , @react-hookz/web, the new library by one of Hope that helps! |
Is your feature request related to a problem? Please describe.
Currently
useMeasure
returns aref
which needs to be assigned a ref in the JSX.This has 2 issues:
ref
is not a realuseRef
for eg. Does not haveref.current
as a prop.Describe the solution you'd like
An API of this shape:
const {width, height ... } = useMeasure({ref: currentRef});
Describe alternatives you've considered
I am using https://github.com/ZeeCoder/use-resize-observer ... in the absence of the above which I want to remove.
The text was updated successfully, but these errors were encountered: