Jim Peeters Jim Peeters - 28 days ago 10
Javascript Question

How to replace /n to linebreaks in react.js?

I am trying to replace every

/n
to a
<br>
tag in
ReactJS
. In my
note.note
object there is a string with multiple
/n
in it.

example note.note:
test\ntest\ntest


What I have tried in
ReactJS
:

{
note.note.split('\n').map(function( item, idx) {
return (
<span key={idx}>
{item}
<br/>
</span>
)
})
}

Answer

Following your logic, try with:

{
    note.note.text.split("\n").map(function(item) {
        return (
            <span>
                {item}
                <br/>
            </span>
         )
    })
}
Comments