how to break lines on \n in Card

UI Components for React
Post Reply
james_sep
Posts: 4
Joined: 19 Apr 2023, 15:29

01 Jun 2023, 17:44

Hi,

I have Card to display text. In the text string, there are \n as line breaker. But <Card> does not break lines on \n.

Here is my code:

<Card /* title={item.status} subTitle={item.date} */>
{item.image && <img src={`assets/demo/images/product/${item.image}`} onError={(e) => (e.target.src = 'https://www.primefaces.org/wp-content/u ... holder.png')} alt={item.name} width={200} className="shadow-2 mb-3" />}
<p>
{item.text}
</p>
<p>
{item.status}
</p>
</Card>

I want {item.text} to break on \n in the text. How can I do that?

Thanks,
James

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

02 Jun 2023, 23:45

You might need to replace `\n` with `<br>` the HTML breaking space?
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

james_sep
Posts: 4
Joined: 19 Apr 2023, 15:29

13 Jun 2023, 20:33

I tried replacing with <br /> , but it doesn't help.

Melloware
Posts: 3717
Joined: 22 Apr 2013, 15:48

13 Jun 2023, 22:06

you have to use dangerouslySetInnerHTML so it translates the breaks?

Code: Select all

<p dangerouslySetInnerHTML={{ __html: item.text }}></p>
PrimeFaces Developer | PrimeFaces Extensions Developer
GitHub Profile: https://github.com/melloware
PrimeFaces Elite 13.0.0 / PF Extensions 13.0.0
PrimeReact 9.6.1

james_sep
Posts: 4
Joined: 19 Apr 2023, 15:29

27 Jun 2023, 19:49

Amazing!
Thank you!

Post Reply

Return to “PrimeReact”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 15 guests