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

275
Vistas
React: Passing a template literal as a prop

I have a component that has a border: string prop (typescript). The way I want to pass in this prop is like below:

<Button border={`'1px solid' ${borderColor}`} />

Where ${borderColor} is a state variable. My prop is working when hard-coding the border, like this:

<Button border="1px solid black" />

But how can I make it work when mixing a string/state variable?

Thanks

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

In this code sample, you can remove the quotes around 1px solid and it should work for you. With template strings, the tick marks (`) are the only string wrappers you need!

Here is a demo showing you how it works: https://codesandbox.io/s/magical-glitter-sbjrqf?file=/src/App.js

about 4 years ago · Juan Pablo Isaza Denunciar

0

Try:

<Button border={`1px solid ${borderColor}`} />

You can read more about template literals here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

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