I have a peace of text in a json that looks like this "I want a new line\nhere".
I have this code that show the text but first replace the \n
with a <br />
:
<p className="subtitle is-5 has-text-white has-text-weight-light summary-text">
{Resume.basics.summary.replace(/(?:\r\n|\r|\n)/g, '<br /> ')}
</p>
And the Resume.basic.summery is this json:
"basics": {
"name": "Greta Thunberg",
"label": "Environmental Activist",
"picture": "images/GretaThunberg 2.jpg",
"x_pictureFallback": "images/GretaThunberg portrait.jpg",
"x_title": "Hey There! Glad you're here",
"summary": "I want a new line\nhere",
"location": {
"country": "Sweden",
"countryCode": "SE",
"region": "Stockholm"
},
"profiles": [
{......................"
The problem is that the new line is never displayed but it works if I do like this:
<p className="subtitle is-5 has-text-white has-text-weight-light summary-text">
<p>I want a new line<br />here</p>
</p>
Then the output is:
I want a new line
here
This is an React app! Any idea why?
here", The `
` is also displayed , any ide? – Erik Aug 05 '20 at 18:43
in your first example is getting rendered as text and not a DOM element. But posting that info will help. – user2263572 Aug 05 '20 at 19:07
I want a new line<br />here
– Erik Aug 05 '20 at 19:16I want a new line
– Erik Aug 05 '20 at 19:23here
 ')} is not generating the html you expected. The "How to safely render html in react? " link @Icepickle posted is probably a good place to start to figure out why. But this is a react string interpolation question, not really a json/html one. – user2263572 Aug 05 '20 at 19:28