In the snippet below there are four divs with 33 characters each. Depending on the width and the word wrapping, the div can take one, two or three lines. What is a good way to calculate this beforehand?
The reason I need this is because I use a React List component (https://bvaughn.github.io/react-virtualized/#/components/List) which accepts a fixed value for the height of a list item or a function to calculate the height of a list item depending on the index. Using that index I can retrieve the text that will be in the div and get the width of the list using JavaScript. From these variables I can hopefully calculate the appropriate height.
.p100 {
width: 100px;
}
.p150 {
width: 200px;
}
<div id="div1" class="p100">
Hello Hello Hello Hello Hello
</div>
<hr>
<div id="div2" class="p100">
abcd abcd abcd abcd abcd abcd
</div>
<hr>
<div id="div3" class="p150">
Hello Hello Hello Hello Hello
</div>
<hr>
<div id="div4" class="p150">
abcd abcd abcd abcd abcd abcd
</div>