javascript - Multiple Inheritance (Styled Components) - Stack Overflow

Please see the code snippets belowIs it possible for ponents to be based on other styled ponents.What

Please see the code snippets below Is it possible for ponents to be based on other styled ponents.

What I would like to do is const HeaderDropDownLi = styled(DropDownLi, HeaderItem)

DropDownLi and HeaderItem are based on a styled ponent called HorizontalListItem

what I'm currently doing is

const HeaderItem = styled(HorizontalListItem)`
    background: #ddd
`;

const HeaderDropDownLi = styled(DropDownLi)`   
    background: #ddd
`;

I tried to implement a wrapper so const H = () => <DropDownLi><HorizontalListItem></DropDownLi>

but it doesn't work that way and I eventually pass a children prop like

    <HeaderDropDownLi 
        onClick={() => onClick(value)} 
        className={activeTab===value ? 'active' : ''}>
        <Dropbtn>{value}</Dropbtn>
        <DropDownContent style={contentStyle}>
            {" "}
            {children}
        </DropDownContent>
    </HeaderDropDownLi>
)``` 

Please see the code snippets below Is it possible for ponents to be based on other styled ponents.

What I would like to do is const HeaderDropDownLi = styled(DropDownLi, HeaderItem)

DropDownLi and HeaderItem are based on a styled ponent called HorizontalListItem

what I'm currently doing is

const HeaderItem = styled(HorizontalListItem)`
    background: #ddd
`;

const HeaderDropDownLi = styled(DropDownLi)`   
    background: #ddd
`;

I tried to implement a wrapper so const H = () => <DropDownLi><HorizontalListItem></DropDownLi>

but it doesn't work that way and I eventually pass a children prop like

    <HeaderDropDownLi 
        onClick={() => onClick(value)} 
        className={activeTab===value ? 'active' : ''}>
        <Dropbtn>{value}</Dropbtn>
        <DropDownContent style={contentStyle}>
            {" "}
            {children}
        </DropDownContent>
    </HeaderDropDownLi>
)``` 
Share Improve this question asked May 4, 2020 at 20:54 user7480665user7480665
Add a ment  | 

1 Answer 1

Reset to default 12

I think you can solved using "css" and exporting a baseStyle and then using it in your ponents.

import styled, { css } from ‘styled-ponents’;

const baseStyles = css`
  background: #ddd
`;

const HeaderItem = styled(HorizontalListItem)`
  ${baseStyles}
`;

const HeaderDropDownLi = styled(DropDownLi)`   
  ${baseStyles}
`;

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743727856a4496925.html

相关推荐

  • javascript - Multiple Inheritance (Styled Components) - Stack Overflow

    Please see the code snippets belowIs it possible for ponents to be based on other styled ponents.What

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信