是否可能使用styled-components来为文本或段落添加样式?如果可以,我怎样将文本传递给组件呢?
例如,我有这个Footer组件:
const Footer = () => (
<footer className="site-footer">
<p className="text"> HELLO</p>
<Copyright
link={'https://hotmail.com'}
text={'HELOO'}></Copyright>
</footer>
);
export default Footer;
我想要从全局类切换到CSS in JS,因此考虑使用styled-components。现在我尝试了以下代码:
export const StyledText = styled.text`
text: Hellooo
color: white;
text-align: center;
`
但是如果我注释掉段落并使用StyledText组件,什么也不会显示。 如果我尝试传递Styled Component text={'HELLO'}
,我的应用程序会崩溃。 如何将页脚转换为使用styled-components的方式?
styled.p
,而不是.text
,这是你想要渲染的 HTML 元素。 - Agney.p
会出错。不过,正确的将文本传递给它的方法是什么?那么styled.text
又是用来做什么的呢?@Agney - user13101751