-
-
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] ref has wrong type #1264
Comments
Same issue, is there any progress? 🤔 |
Any updates on this? |
You can override the default generics ( const [ref] = useMeasure<HTMLDivElement>() |
If I'm not mistaken, you'd have to use |
Happy New Year! 🎉 I still can't upgrade I've just rebased the PR on |
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! |
@JoeDuncko Thanks for the tip! Either of these solutions worked for me when using @react-hookz/web. First, this StackOverflow answer: import { useMeasure } from "@react-hookz/web/esm"
function ComponentName() {
const [measurements, ref] = useMeasure()
return <div ref={ref as React.RefObject<HTMLDivElement>}>{" "}</div>
} Or, second, paying more attention to the import { useMeasure } from "@react-hookz/web/esm"
function ComponentName() {
const [measurements, ref] = useMeasure<HTMLDivElement>()
return (<div ref={ref}>{" "}</div>)
} |
What is the current behavior?
The code below errors:
Reproduced in: https://codesandbox.io/s/purple-bash-btzpp?file=/src/App.tsx
What is the expected behavior?
Type
UseMeasureRef<E>
should be(instance: E | null) => void
, though React's built-inRefCallback<T>
type could probably be used as well.A little about versions:
@types/react
: 16.9.35react-use
: 15.1.1The text was updated successfully, but these errors were encountered: