最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - how to make a new line for react - Stack Overflow

programmeradmin7浏览0评论

Refer to the code below:

<item
     itemName={"laptop"}
     itemDescription={"- XXXX \n - PPPP"}    // how could I make a new line for this?
/>

\n is not working at this

Refer to the code below:

<item
     itemName={"laptop"}
     itemDescription={"- XXXX \n - PPPP"}    // how could I make a new line for this?
/>

\n is not working at this

Share asked Aug 3, 2020 at 15:41 koko kakoko ka 1174 silver badges18 bronze badges 1
  • Does this answer your question? How can I insert a line break into a <Text> ponent in React Native? – gbalduzzi Commented Aug 3, 2020 at 15:43
Add a ment  | 

1 Answer 1

Reset to default 4

You can do something like this:

 {text.split(“\n”).map(function(item) {
    return (
       {item}
       <br/>
    )
 })}

In your particular case it would look like this:

 itemDescription={<>XXXX <br /> - PPPP</>}  

If your ponent takes nodes in that property, and not a string.

React doesn't use strings to create the HTMl, and HTML ignores line breaks, so you need to turn that string into JSX with line breaks, or paragraphs.

发布评论

评论列表(0)

  1. 暂无评论