ReactJS render string with non-breaking spaces
Instead of using the
HTML entity, you can use the Unicode character which
refers to (U+00A0 NON-BREAKING SPACE):
<div>{myValue.replace(/ /g, "\u00A0")}</div>
I know this is an old question, and this doesn't exactly do what you asked for, but rather than editing the string, what you want to achieve is probably be solved better using the CSS white-space: nowrap
attribute:
In html:
<div style="white-space: nowrap">This won't break lines</div>
In react:
<div style={{ whiteSpace: 'nowrap' }}>{myValue}</div>