Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

363
Visualizações
Split a string with HTML <br> tag into multiline string

I've a string that contains html break tag to split the string as I would like to split the string into multiple lines but it doesn't seem to render the string as multi-line in UI. How can I achieve the following?

testString = "This is line one<br>This is line two<br>This is line three"

Expected Output:

This is line one
This is line two
This is line three

I read about dangerouslysettinginnerHTML but don't want to use it in my code. As far as split is concerned what I did was I tried

text.split('<br>').map(each => each + <br>)

but that didn't work. Any hint or help would be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The easiest way to do this outside of dangerouslySetInnerHTML is split and flat-map the string to an array of JSX elements.

{testString
  .split(/<br ?\/?>/)
  .flatMap((line, i) => [line, <br key={`line-${i}`} />])}

The regex delimiter is designed to split on any form of <br>, <br/> or <br />.

Edit tender-taussig-uc6y50

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda