1 | initial version |
HTML tags can be transmitted through props in React by using the dangerouslySetInnerHTML
prop. This prop is used to set the innerHTML
property of a node, which can contain HTML tags. Here's an example:
function MyComponent({htmlContent}) {
return <div dangerouslySetInnerHTML={{__html: htmlContent}} />;
}
<MyComponent htmlContent="<p>This is some <b>bold</b> text</p>" />
This will render the HTML content passed in as a prop as regular HTML tags within the div
element. However, it's important to note that using dangerouslySetInnerHTML
can pose a security risk if the HTML content comes from an untrusted source, as it can potentially contain malicious scripts or code.