Ok so as the OP asked, here's how one can convert any SVG file to a React Component. This gives you much more control over the SVG and even gives you the power to animate it (i.e. react-popmotion, react-animated, etc) or to update path depending on state. Another cool benefit is that this way you don't need any webpack/gulp/grunt/anything plugin to inline SVGs as they are inlined by React itself ;).
First, open your SVG file, copy the code.
Then, create a new file into components/icons/CheckboxIcon.js
or similar.
Here's an example of a CheckBoxIcon I made for a project at work:
import React from 'react'
import PropTypes from 'prop-types'
const CheckBoxIcon = props => (
<svg
style={{ width: 24, height: 24 }}
viewBox={'0 0 24 24'}
onClick={props.onClick}
>
<path
fill={props.checked ? '#1E82E4' : 'rgba(0,0,0,.67)'}
d={
props.checked
? 'M10,17L5,12L6.41,10.58L10,14.17L17.59,6.58L19,8M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3Zs'
: 'M19,3H5C3.89,3 3,3.89 3,5V19A2,2 0 0,0 5,21H19A2,2 0 0,0 21,19V5C21,3.89 20.1,3 19,3M19,5V19H5V5H19Z'
}
/>
</svg>
)
CheckBoxIcon.propTypes = {
checked: PropTypes.bool,
onClick: PropTypes.func
}
CheckBoxIcon.defaultProps = {
checked: false,
onClick: () => null
}
export default CheckBoxIcon
Then just import it as a regular React component, i.e.:
import CheckBoxIcon from '../icons/CheckBoxIcon';
render () {
return (
<div>
{/* My components... */}
<CheckBoxIcon />
<CheckBoxIcon checked={true} />
</div>
)
}
For more informations, feel free to check this article on dev.to: https://dev.to/nishanbajracharya/using-svg-icons-components-in-react-163k