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

158
Visualizações
What is the best way to make a wrapper for component exports where I can pass in a className

I am trying to create a wrapper function that I can pass in an imported component and a string that I can then re-export without having to make a new component each time and add the className manually.

I am using radix ui components and tailwindcss and want to achieve something like this export const DropdownContent = styled(DropdownPrimitive.Content, styles.content); which would essentially allow me to style the radix component without all the boilerplate.

the function is styled, the left-hand side is the radix component and the right would either be tailwind from a css file or could be a string "bg-blue-100"

I have got the following to work but storybook doesn't like it and if I update the styles it breaks the component on hot reload.

import clsx from "clsx";

type Styled = (
  Component: React.FC<any>,
  styles: string
) => React.FC<{ className: string }>;

export const styled: Styled = (Component, styles) => {
  return function StyledComponent({ className, ...props }) {
    return <Component {...props} className={clsx(styles, className)} />;
  };
};

Thanks in advance for any help.

about 4 years ago · Santiago Trujillo
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