Skip to content

Instantly share code, notes, and snippets.

@stasgavrylov
Created April 22, 2018 11:14
Show Gist options
  • Save stasgavrylov/39c4f003d3f0f119750e12209017e3fa to your computer and use it in GitHub Desktop.
Save stasgavrylov/39c4f003d3f0f119750e12209017e3fa to your computer and use it in GitHub Desktop.
React SVG wrapper component
svg {
fill: white;
stroke: currentColor;
}
import React from 'react';
import classNames from 'classnames';
import './SvgIcon.css';
export class SvgIcon extends React.Component {
static defaultProps = {
icon: '',
width: 16,
height: 16,
strokeWidth: 24,
};
render() {
const { className, icon, ...attrs } = this.props;
return (
<svg className={classNames('svg-icon', className, icon)}
{...attrs}
>
<use xlinkHref={`/icons.svg#${icon}`} />
</svg>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment