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

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