Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
¿Cómo crear un componente de texto donde la primera palabra de la oración esté en negrita?

Estoy tratando de crear un componente de texto donde la primera palabra de la oración esté en negrita. En este momento, con mi solución, cuando un usuario ingresa "Consejos: vacaciones favoritas", obtengo " Consejos: vacaciones favoritas", donde el resto de la oración se vuelve desordenado y no se crea espacio después de Consejos:. Esta no es una solución elegante. Pensé en crear otro componente como TextBold y usarlo así < Text >< TextBold >Tips:< /TextBold > Your Vacation< /Text >, pero parece innecesario. ¿Hay alguna manera de hacer que esto funcione solo dentro del componente Texto?https://codesandbox.io/s/text-component-v2dbt?file=/src/App.tsx

 import * as React from "react"; export interface TextProps { children?: string; } export const Text: React.FunctionComponent<TextProps> = ({ children }: TextProps) => { return ( <> <span style={{ fontWeight: "bold" }}>{children?.split(" ")[0]}</span> <span>{children?.split(" ").slice(1)}</span> </> ); }; export default function App() { return ( <div> <Text>Tips: favourite vacation</Text> </div> ); }
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Podría hacer uso del índice de caracteres del primer espacio y .substring

 export const Text: React.FunctionComponent<TextProps> = ({ children = "" }: TextProps) => { const firstSpaceIndex = children.indexOf(" "); return ( <> <span style={{ fontWeight: "bold" }}> {children.substring(0, firstSpaceIndex)} </span> <span>{children.substring(firstSpaceIndex)}</span> </> ); };

Editar componente de texto (bifurcado)

about 4 years ago · Juan Pablo Isaza Report

0

Probar

 <span style={{ fontWeight: "bold" }}>{children?.shift()}</span> <span>{children?.split("").slice(1)}</span>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!