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

91
Views
Create dynamic tags with Styled Components

Is there a way to create a dynamic tag using styled-components? For example:

const MyComponent = styled(CustomTag)``;

<MyComponent element="h1" />
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can use as prop by default on components created with styled-components. If in your example CustomTag is also a styled-component that styles a native element (e.g.:)

const CustomTag = styled.h1`
  color: red;
`;

then you can do

const MyComponent = styled(CustomTag)`
  font-size: 64px;
`;

<MyComponent as="span">Something</MyComponent>

and you'll end up with a <span> tag with font-size of 64px and red text color. Of course you can also use as prop on CustomTag so you don't necessarily need MyComponent.

about 4 years ago · Juan Pablo Isaza Report

0

Maybe this will help you:

Add you code in your typescript

class Test extends HTMLElement {
    connectedCallback() {
        this.innerHTML = `<h1>Hello World...</h1>`;
        this.style.color = "red";
    }
}

customElements.define('test', Test);

after compiling refer the js file in you HTML and you can use it like <test></test>

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!