question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`useMeasure` types fail with the `@types/react` package version `17.0.41`

See original GitHub issue

What is the current behavior?

The useMeasure types fail with the @types/react package version 17.0.41.

Steps to reproduce it and if possible a minimal demo of the problem. Your bug will get fixed much faster if we can run your code and it doesn’t have extra dependencies other than react-use. Paste the link to your JSFiddle or CodeSandbox example below:

https://codesandbox.io/s/broken-hooks-ps75vr?file=/src/App.tsx

What is the expected behavior?

The project compiles correctly!

A little about versions:

  • OS: Mac OSX 12.3
  • Browser (vendor and version): Safari 15.4
  • React: 17.0.2
  • react-use: 17.3.2
  • Did this worked in the previous package version? No

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:8

github_iconTop GitHub Comments

3reactions
BABA983commented, Mar 27, 2022

i think the reason is this UseMeasureRef type export type UseMeasureRef<E extends Element = Element> = (element: E) => void; the Element can be null just fix the type like this export type UseMeasureRef<E extends Element = Element> = (element: E | null) => void; the error will gone

2reactions
ronaldruzickacommented, Sep 9, 2022

I take it back, it works if you use generic with useMeasure

const [ref, { width }] = useMeasure<HTMLDivElement>();
Read more comments on GitHub >

github_iconTop Results From Across the Web

@types/react - npm
Start using @types/react in your project by running `npm i ... TypeScript icon, indicating that this package has built-in type declarations.
Read more >
Type errors because of types/react~17. · Issue #17101 - GitHub
I have created a new project with the typescript template, and I get type errors with the react navigation component. Stack.Navigator' cannot be...
Read more >
Next.js is not recognizing '@types/react' - Stack Overflow
js app with npm run dev I get an error message saying that I don't have the required packages to run Next with...
Read more >
@types/react | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
React v16.0 – React Blog
New render return types: fragments and strings · Better error handling · Portals · Better server-side rendering · Support for custom DOM attributes....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found