在 react / html 中呈现新行 (\n)

rendering new line (\n) as it is in react / html

我正在尝试将换行符呈现为 \n,但它们会自动转换为换行符。

const text = "hi\nhi"
<div>{text}</div>

这被呈现为:

hi
hi

如何在 react/html 中不带任何格式将文本实际显示为 "hi\nhi"?谢谢

使用双反斜杠 "hi\nhi",而不是 "hi\nhi"