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

Viewed 264

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

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

Related