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
1 Answer
Reset to default 12I 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
评论列表(0条)