-1

I store every text in my application in a settings.ts file, but I need to add some breaklines and \n appears not to work. Is there any other way I should could these breaklines? I'm working with Next.js, React and TypeScript.

export const text = 'this is my text that \nshould have a breakline'

<div>{text}</div>
juliomalves
  • 42,130
  • 20
  • 150
  • 146

2 Answers2

0

Instead of using \n, you can use another option <br/>.

Mart
  • 36
  • 2
0

You can set white-space to pre-wrap

const text = 'this is my text that \nshould have a breakline'

const App = () => <div className="break">{text}</div>

ReactDOM.render(
    <App />,
    document.getElementById("root")
);
.break {
  white-space: pre-wrap;
}
<div id="root"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.development.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.development.js"></script>
kennarddh
  • 2,186
  • 2
  • 6
  • 21