Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display an array of strings in react component

I'm trying to display an array of strings on separate lines in my react component by doing the following:

       <div>
          {this.props.notifications.join('\n')}
      </div>

However, this doesn't seem to be working. this.props.notifications is an array of strings that I want to render in the div. Does anyone know how I can work around this?

like image 256
blazerix Avatar asked Oct 21 '25 13:10

blazerix


1 Answers

What about using a <p /> to render each line?

<div>
   {this.props.notifications.map(txt => <p>{txt}</p>)}
</div>

That will render each element in a different paragraph.

like image 179
Crysfel Avatar answered Oct 23 '25 04:10

Crysfel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!