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

147
Views
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
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!