How to append custom classNames to SVG components with svgProps.className
specified?
#770
Answered
by
jamonserrano
SevenOutman
asked this question in
Q&A
-
Hi, I'm using SVGR in my webpack project with the following config: {
icon: true,
svgProps: {
fill: 'currentColor',
className: 'rs-icon',
},
} Note that I add an When I use those SVG components and need to add some more classNames, the <StarIcon className="mr-1" /> // -> results in class="mr-1" instead of class="rs-icon mr-1" So I'm wondering how I can append custom classNames to these SVG components while having this common |
Beta Was this translation helpful? Give feedback.
Answered by
jamonserrano
Sep 28, 2022
Replies: 1 comment 2 replies
-
{
expandProps: 'start' // (1)
svgProps: {
className: `{props.className ? props.className + ' rs-icon' : 'rs-icon'}`, // (2)
},
} (1) prevents external props from overriding the ones set in |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
gregberge
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
(1) prevents external props from overriding the ones set in
svgProps
.(2) appends the class name to the ones passed in.