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>
);
}