Closed damianobarbati closed 6 years ago
The height needs to be known in advance, as this is how the height of the scrollable list can be calculated.
Reading from computed style would be slow and expensive, as you would need to wait for the DOM node to be mounted to know it's computed height.
Personally I prefer the approach described here: https://github.com/coderiety/react-list#itemsizeestimatorindex-cache
What it does is that:
itemSizeEstimator
function. This determines how much space is added to the end of the list for not-yet-reached items. However, once those items are scrolled to, we then know the real height so update the list height to match.I know react-tiny-virtual-list has the estimatedItemSize
prop, which is similar. However, it's not as good because it's a "one number for every item" property, instead of an estimator-function which can adjust based on, for example, the number of characters in a chat message, to get a more accurate height estimate (thus causing less scroll janking).
What about adding the possibility to not give an "height" prop and derive it from element.style.height?
Use case:
I already deal with height in my classes for proper UI and it's redundant to add the logic twice into renderer.