How to add br tag in this situation?
import './App.css';
export default function App() {
return (
<main>
{`aaaa <br />bbbb`}
</main>
);
}
How to add br tag in this situation?
import './App.css';
export default function App() {
return (
<main>
{`aaaa <br />bbbb`}
</main>
);
}
2
Answers
Don’t use a literal string.
If you must use a HTML string, you can use
dangerouslySetInnerHTML
, but know that this is generally not recommended.Options 1:
dangerouslySetInnerHTML
For general use cases,
dangerouslySetInnerHTML
should be fine. Beware that setting HTML from public text/strings is a major risk due to XSS attack.Options 2:
html-react-parser
You may also try this library in place of
dangerouslySetInnerHTML
. You may do something like this –