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

111
Vistas
How to add conditionally props to a component for a button in next.js project

there fellow overflowers!

I have a question about the next.js project I am working on.

I have a Button component that has an icon but instead of waiting for a prop from the icon (in my application only one icon will be used) to pass a flag, eg. hasIcon.

Before returning the component I want to set the props that should be added conditionally according to the value of the above flag.

If the value of the flag is true, the following part startIcon={<ArrowForwardIcon />} should be added. How can I do that with JavaScript Spread Operator to add conditionally props to a component?

Here is the code of the Button component:

import * as React from "react";
import MUIButton from "@mui/material/Button";
import ArrowForwardIcon from "@mui/icons-material/ArrowForward";

export default function Button({ variant, label, icon }) {
  // I want to make a const here
  return (
    <MUIButton variant={variant} startIcon={<ArrowForwardIcon />}>
      {label}
    </MUIButton>
  );
}
about 4 years ago · Juan Pablo Isaza
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