Created
September 29, 2016 08:33
-
-
Save blivesta/be252ac79511602f35a83a4882c21158 to your computer and use it in GitHub Desktop.
Use SVG Sprite for React
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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