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

108
Visualizações
How to avoid breaking lines in React fragments

I have the following function which generate a fragment:

const f = (first, last) => {
    <>{first}{first.indexOf("\'") > 0 ? "" : " "}<i>{last}</i></>
}

Then, I use the function in a piece of HTML

<Row>
   here is {f("xxx","yyy")}.
</Row>

I expected exactly the following output:

<div>
   here is xxx yyy.
</div>

but the result in the browser debug is the following:

<div> (flex)
"here is "
"xxx"
<i>yyy</i>
"."
</div>

and the browser displays as:

here is
xxx
yyy (<- this in italic)
.

I tried to wrap in a <span className="nowrap"> with

span .nowrap {
    white-space: nowrap;
  }

with no success.

Can someone provide some help?

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

0

The inspector is just showing you the text nodes. You can join up some of these nodes but there's an element node right in between the period and the first part of your text. There's no way around that.

{first}{first.indexOf("\'") > 0 ? "" : " "}

can be written as:

{`${first}${first.indexOf("\'") > 0 ? "" : " "}`}

But like I said, the last . will be a text node after the <i> element.

That being said, the browser (as in the document viewport) should display these text nodes without the line break.

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