Let's assume that you have a text with line breaks such as:
javascriptlet text = `Hello\nMy name is Erik\nI'm from Barcelona`
If you try to render the previous text in React:
jsximport React, { useState } from 'react' const Text = () => { const [text, setText] = useState(`Hello\nMy name is Erik\nI'm from Barcelona`) return( <div className = 'Text'> {text} </div> ) }
You'll get the following output:
terminalHello My name is Erik I'm from Barcelona
Add this line to the CSS to print the line breaks:
CSS.Text{ white-space: pre-wrap; }
Result:
terminalHello My name is Erik I'm from Barcelona
Hi, I'm Erik, an engineer from Barcelona. If you like the post or have any comments, say hi.