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

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

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