我正在为我的所有样式使用 styled-components,并且想知道如何将样式从我的父组件 footer.jsx 传递到我的可重用子组件联系人作为道具。
我尝试了几种不同的方法,将一个字符串作为道具传递,然后将其传递给一个样式化的组件以进行更新,background-image{this.props.icon}
但这不起作用,而且我尝试过的当前方式也没有渲染任何东西.
https://www.webpackbin.com/bins/-Kg0-scl1gRf4UTOaK-Y
页脚.jsx
import React from 'react'
import styled from 'styled-components'
import Contact from '../../molecules/Contact'
const Icon1 = styled.span`
margin-top:8.333333px;
background:url(icon1.png);
width:25px;
height:25px;
`
const Icon2 = styled.span`
margin-top:8.333333px;
background:url(icon2.png);
width:25px;
height:25px;
`
export default class MainFooter extends React.Component {
render() {
return (
<Wrapper>
<Contact icon={<Icon1 />} />
<Contact icon={<Icon2 />} />
</Wrapper>
)
}
}
联系方式.jsx
export default class Contact extends React.Component {
return (
<A href="/">
<Wrapper>
<ColLeft> {this.props.icon}</ColLeft>
</Wrapper>
</A>
)
}
}