Home > OS >  how to add line breaks in react js?
how to add line breaks in react js?

Time:08-13

I want to send a whatsapp message using this code below, but I don't know how to add line breaks in the message. I tried using \n but it still appears as 1 line.

the function

export function sendWhatsApp(phone='', msg='') {
  let phoneWithCountryCode = `62${ltrim(phone, '0')}`; // 628123456789
  let mobile = ` ${phoneWithCountryCode}`;
  let url = `whatsapp://send?phone=${mobile}&text=${msg}`;

  Linking.openURL(url).then((data) => {
    console.log('WhatsApp Opened');
  }).catch(() => {
    alert('Please make sure WhatsApp installed on your device');
  });
}
// end export function sendWhatsApp

how I call the function

let msg = `Hello \n
This is first line of message \n
this is the second line`
;
sendWhatsApp('8123456789', msg);

CodePudding user response:

Use "\r\n", it will work.

CodePudding user response:

I suspect it's because \ is encoded in the URL? can you try \n instead of \n?

  • Related