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

93
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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