Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

107
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda