I want to style an MUI Button using styled-components. I want to pass variant='outlined' as a prop to the component. Here's what I'm trying:
export const StyledButton = styled(Button).attrs(() => ({
variant: 'outlined',
}))
and it throws this error:

To pass attributes you have to do something like this:
const StyledButton = styled(Button)`
background-color: #6772e5;
color: #fff;
box-shadow: 0 4px 6px rgba(50, 50, 93, 0.11), 0 1px 3px rgba(0, 0, 0, 0.08);
padding: 7px 14px;
&:hover {
background-color: #5469d4;
}
`;
export default function StyledComponent() {
return (
<StyledButton variant="outlined">Customized</StyledButton>
);
}
For more, you can refer to offical Doc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With