How to get reference of a child tag that was added via dangerouslySetInnerHTML in React

  html, javascript, reactjs

I have a div that use dangerouslySetInnerHTML to set some text that come from the server. Something like this:

<Wrapper>
  <div
    ref={previewRef}
    dangerouslySetInnerHTML={{ __html: preview }}
  />
</Wrapper>

The preview content it’s something like <p> Some context </p>. I need to access offsetHeight and scrollHeight of that rendered p tag instead of the div.

Source: Ask Javascript Questions

LEAVE A COMMENT