有没有一种方法可以使用styled components样式化导入到React中的SVG组件,例如以下方式:
我尝试过以下做法:
import { ReactComponent as Icon } from "./resources/somerandom.svg"
? 我已经将我的个人项目转换为styled components,但是无论什么原因,样式都无法显示在组件上。我尝试过以下做法:
import { ReactComponent as Icon } from "./resources/somerandom.svg"
import styled from "styled-components"
const IconWrapper = styled.svg`
fill: white;
width: 20px;
`
const RandomComponent = () => (
<IconWrapper>
<Icon/>
</IconWrapper>
)
我知道可以直接将样式传递给SVG组件,但我想要一个使用styled components的解决方案。 如果这篇文章让人感到困惑,可能是因为我已经醒来了很长时间了。谢谢大家的帮助。