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

274
Views
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 answers
Answer question

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 Report

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 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!