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.

measureRef gives wrong size at first render

See original GitHub issue

Hi, I am trying to use react-virtual to render a dynamic-height list. When I pass measureRef to my list item wrapper like <div ref={measureRef}><ListItem /></div> it calculates the height of each visible list item as 48px. But this value is not correct. Calculation becomes correct when I start scrolling for the first time to trigger a change on visible portion of the list.

When I pass the ref using a arrow function like <div ref={element => measureRef(element)}><ListItem /></div> it calculates and renders correctly.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:9
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
luonglearnstocodecommented, Jan 19, 2021

image Thank you for this issue. However, typescript complains about this. Any ideas on how to resolve this?

2reactions
babycourageouscommented, Jan 4, 2021

@sarioglu - this issue advice saved me. I was having trouble with lists of a certain size not displaying correctly until i scrolled as well. This arrow function fix solved the problem!

Read more comments on GitHub >

github_iconTop Results From Across the Web

measureRef gives wrong size at first render · Issue #85 - GitHub
Hi, I am trying to use react-virtual to render a dynamic-height list. When I pass measureRef to my list item wrapper like it...
Read more >
How can I respond to the width of an auto-sized DOM element ...
We're doing all of our 3rd-party SVG rendering in shouldComponentUpdate, but you cannot set state or properties on yourself or other child components...
Read more >
Use ref callbacks to measure React component size
You can use ref callbacks to measure the rendered size of React components, did you know? It's a neat little trick. Here's how...
Read more >
API Reference | React Virtual - TanStack
Optional; Defines initial rect size of list. Can be used for server-side rendering. useObserver: Function(parentRef: React.useRef(DOMElement), initialRect?:
Read more >
How to Get The Size of a React Native View Dynamically
React Native provides a Dimensions API that can be used to get the width ... the first render call, but the whole point...
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