Extending styles with styled-components not working

后端 未结 2 1004
礼貌的吻别
礼貌的吻别 2021-02-19 10:59

I\'m trying to extend styles for a react component using styled-components but is not working. AFAIK, I\'m doing it the right way, but perhaps I\'m missing somethin

2条回答
  •  名媛妹妹
    2021-02-19 11:46

    As stated in documentation:

    The styled method works perfectly on all of your own or any third-party components, as long as they attach the passed className prop to a DOM element.

    Example

    // This could be react-router-dom's Link for example, or any custom component
    const Link = ({ className, children }) => (
      
        {children}
      
    );
    
    const StyledLink = styled(Link)`
      color: palevioletred;
      font-weight: bold;
    `;
    
    render(
      
    Unstyled, boring Link
    Styled, exciting Link
    );

    Ref: https://www.styled-components.com/docs/basics#styling-any-component

提交回复
热议问题