Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda