如何在反应组件中显示字符串数组

bla*_*rix 2 javascript typescript reactjs

我正在尝试通过执行以下操作在我的反应组件中的单独行上显示一个字符串数组:

       <div>
          {this.props.notifications.join('\n')}
      </div>
Run Code Online (Sandbox Code Playgroud)

但是,这似乎不起作用。this.props.notifications 是我想在 div 中呈现的字符串数组。有谁知道我该如何解决这个问题?

Cry*_*fel 10

使用 a<p />来渲染每一行怎么样?

<div>
   {this.props.notifications.map(txt => <p>{txt}</p>)}
</div>
Run Code Online (Sandbox Code Playgroud)

这将在不同的段落中呈现每个元素。