I need to insert a React component into a String variable that contains html content. This variable will be render with dangerouslySetInnerHTML.
I replace my placeholder "!#ShareButton" with the content of my React component, but it renders [object Object] instead of the component itself
React component:
const ShareThis = ({ text }) => {
return (
<div class="one-line">{text}</div>
)}
export default ShareThis
var content (string variable with html content)
<p>Text 1</p>
!#ShareButton
<p>Text 2</p>
Page:
const htmlcontent = content.replace(/!#ShareThis/g,
<ShareThis
text="Hello"
/>)
return (
<div dangerouslySetInnerHTML={{ __html: htmlcontent }} />
)
Result:
Text 1
[object Object]
Text 2
Do you know how to insert a React component into a String variable with html content?