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

190
Views
How to create a custom action bar with flexible actions in React (with TypeScript)?

I would like to create a custom action bar with flexible actions that can be set via props or similar.

This is how I implemented it (and it's working like expected), but I'm wondering if there's a better or cleaner way in React (with TypeScript).

Especially when the actions increase over time. Then I would have to add more booleans that would eventually make things confusing.

type CustomBarProps = {
    withButton: boolean,
    withCheckbox: boolean,
    withRadio: boolean,
}

export const CustomBar = ({
    withButton = false,
    withCheckbox = false,
    withRadio = false,
}: CustomBarProps) => {
    const features: JSX.Element[] = [
        withButton && <Button />,
        withCheckbox && <Checkbox />,
        withRadio && <Radio />,
    ]
    return <Bar features={features} />
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

yeah you don't need to explicitly define each prop has to be false you can also do it like this

type CustomBarProps = {
  Button?: boolean;
  Checkbox?: boolean;
  Radio?: boolean;
};

export const CustomBar: React.FC<CustomBarProps> = ({ Button, Checkbox, Radio }) => {
  const features = [Button && <Button />, Checkbox && <Checkbox />, Radio && <Radio />];
  return <Bar features={features} />;
};
about 4 years ago · Juan Pablo Isaza Report
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!