'React / Formatting JSON Object with line breaks
Is it possible to have line breaks within one value of an JSON Object?
I tried with \n with br-tag and with template literals like bla bla ${\n} bla bla bla, but it's not working.
My code looks like this in the Object
export const Data = [
{
id: 1,
item: 'blablabla',
detail:
'bla bla bla. <here I want a line break> bla bla bla'
}]
Thanks for your help
Solution 1:[1]
The best approach I found is to use the css property white-space: "pre-wrap"; , it will let you use line breaks without <br/>
I would also recommend to write the text with template literals so you don't need to use \n
export const Data = [
{
id: 1,
item: 'blablabla',
detail: "bla bla bla. \n bla bla bla",
betterDetail:
`it will
also
works like this
`
}]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RodrigoSosa |
