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

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