useResizeDetector with targetRef - version 1.3.1
See original GitHub issueHi,
if have the following problem with the new targetRef:
If I use:
const {width, height} = useResizeDetector({targetRef: someRef})
width and height are always undefined for my component
Whereas if I use:
const {width, height} = useResizeDetector({targetRef: someRef, onResize: ()=>{}})
I get the correct dimensions of the someRef component,… which doesn’t really make sense to me.
I suspect react-resize-detector is not reacting to ref changes properly.
Adding ref.current
to the dependency array [refreshMode, refreshRate, refreshOptions, handleWidth, handleHeight, onResize]
(which helps in my case) seems to be wrong and “wrong”
Any ideas?
Cheers,
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:18 (8 by maintainers)
Top Results From Across the Web
useResizeDetector with targetRef - version 1.3.1 #130
onResize is an anonymous function. JS creates a new instance of this function every time the parent component rerenders. And, as a result,...
Read more >A Cross-Browser, Event-based, Element Resize Detection for ...
useResizeDetector with targetRef - version 1.3.1. Hi, if have the following problem with the new targetRef: If I use: const {width, ...
Read more >react-resize-detector - githubmemory
Warning useLayoutEffect in SSR · Return support to React 16^ · Stray console logs · useResizeDetector with targetRef - version 1.3.1.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Aha, I see…
You’re trying to implement the approach Dan mentioned in this comment , right?
Does it change the library API? I mean that you can’t pass
targetRef
anymore, right? Can you provide a code snippet of how it’s intended to be used?Similar to the above, I found that I was getting an initial delay before the width and height would get assessed. Using something in the current react docs, I was able to fix it by avoiding
useRef
altogether as they recommend:I wonder if you should do similar. I’ve asked if they can add an equivalent example to the beta docs, because I might be relying on some legacy ref thing here.