3

I can change the fill of an SVG using it as a component

import { ReactComponent as Icon} from '../assets/icon.svg'
...
<Icon fill='#000' />

With "current" on the fill field inside the SVG file

<path fill="current" />

But I have two differents path. How can I set them to have differents fills?

<path fill="current" />
<path fill="otherColor?" />

1 Answer 1

3

I managed to use different colors by creating a component that return that SVG as JSX passing colors as props

const Icon = ({inside, outside}) => (
  <svg>
    <g>
      <path fill={outside} />
      <path fill={inside} />
    </g>
  </svg>
)
<Icon outside='#000' inside='red'/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.