【发布时间】:2021-03-23 21:47:33
【问题描述】:
如何使用与F.Link 组件相同的样式设置News 组件的样式?我想设置此组件的样式,同时将其作为自己的功能组件分开。
import styled from 'styled-components';
const F = {
Container: styled.div`
...
`,
Text: styled.p`
...
`,
Link: styled.a`
transition: color 0.5s linear;
text-decoration: none;
color: ${(props) => (props.isDark ? '...' : '...')};
`,
};
export const Footer = ({ isDark }) => {
const isPhone = window.matchMedia('...').matches;
const News = () => (
<>
<a href='#'>News</a>
</>
);
return (
<F.Container>
<F.Text>Thanks for stopping by
<F.Link isDark={isDark} href='#'>Contact</F.Link>
{isPhone ? (
<></>
) : (
<News/>
)}
</F.Text>
</F.Container>
);
};
【问题讨论】:
-
您想要设置样式的每个组件都必须接受
className属性并将其传递给 DOM 元素。