Add Classes to Styled Component

后端 未结 1 1344
庸人自扰
庸人自扰 2021-01-12 23:42

I am trying to add class names to a React Component to make it easier for me to customize that component using Styled Components. Here is a simplified outline of the compone

相关标签:
1条回答
  • 2021-01-13 00:00

    You need to provide className for the wrapper/container as styled-component injecting the styles through it:

    const SignupForm = ({ className }) => (
      <form className={className}>
        <input className="input" />
        <button className="button">Button</button>
      </form>
    );
    
    const Form = styled(SignupForm)`
      .input {
        background-color: palegreen;
      }
    
      .button {
        background-color: palevioletred;
      }
    `;
    

    0 讨论(0)
提交回复
热议问题