JSFiddle - React, Tailwind, and code Playground
HTML
<div class='wrap'><img src='https://happytailsdiscountpetemporium.com/wp-content/uploads/2015/08/5-9-cat-image-150x150.jpg' width="400">text text text text text text</div>
<div class='wrap'><img src='https://happytailsdiscountpetemporium.com/wp-content/uploads/2015/08/5-9-cat-image-150x150.jpg'>text text text text text text</div>
<div class='wrap'><img src='https://happytailsdiscountpetemporium.com/wp-content/uploads/2015/08/5-9-cat-image-150x150.jpg'>text text text text text text</div>
<div class='wrap'><img src='https://happytailsdiscountpetemporium.com/wp-content/uploads/2015/08/5-9-cat-image-150x150.jpg'>text text text text text text</div><div class='wrap'><img src='https://happytailsdiscountpetemporium.com/wp-content/uploads/2015/08/5-9-cat-image-150x150.jpg'>text text text text text text</div>
CSS
.wrap{
word-wrap:break-word;
background:#ccc;
display:inline-block;
margin:10px;
}
JavaScript
var wraps = document.querySelectorAll(".wrap");
for(var i = 0, l = wraps.length; i < l; i++){
wraps[i].style.width = wraps[i].getElementsByTagName('img')[0].clientWidth + 'px';
}