Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

92
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda