Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass prop to Material-UI component using styled-components

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: enter image description here

like image 707
Fowad Avatar asked Nov 20 '25 07:11

Fowad


1 Answers

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

like image 68
Yash Sangai Avatar answered Nov 21 '25 22:11

Yash Sangai