Skip to content

Instantly share code, notes, and snippets.

@blivesta
Created September 29, 2016 08:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blivesta/be252ac79511602f35a83a4882c21158 to your computer and use it in GitHub Desktop.
Save blivesta/be252ac79511602f35a83a4882c21158 to your computer and use it in GitHub Desktop.
Use SVG Sprite for React
import React from 'react'
class SvgIcon extends React.Component {
static get propTypes () {
return {
className: React.PropTypes.string,
iconName: React.PropTypes.string,
viewBox: React.PropTypes.string
}
}
static get defaultProps () {
return {
className: 'icon',
iconName: '',
viewBox: '0 0 32 32'
}
}
render () {
const useTag = `<use xlink:href=${this.props.iconName} />`
return (
<svg
viewBox={this.props.viewBox}
className={this.props.className}
dangerouslySetInnerHTML={{__html: useTag}}
/>
)
}
}
export default SvgIcon
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment