In a react application I am working on there is a condition that:
when a string has a new line character the
<p>{string}</p>
tag in which string is to be displayed should be replaced with HTML new line character.
But of course this does not work.
Things I have already tried but did not work for me:
const string = Hello\nHii
<p>{string.replace('\n', <br />)}</p>
output:
Hello<br />Hii
<p>{string.replace('\n', &)}</p>
output:
Hello Hii
I found the above suggestions in the following answers:
{string}
` for each element of the resulting split? – Daniel Arthur Oct 31 '18 at 09:12