Skip to content

Instantly share code, notes, and snippets.

@averyvery
Created April 14, 2015 18:42
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 averyvery/ee758c0b0e6fda74cdc7 to your computer and use it in GitHub Desktop.
Save averyvery/ee758c0b0e6fda74cdc7 to your computer and use it in GitHub Desktop.
svg.jsx
// option for inlining (for index)
// option for caching (for SVGs used more than once)
export default React.createClass({
getInitialState() {
return {
svg: ''
}
},
componentDidMount() {
const request = new XMLHttpRequest()
request.open('GET', require(`../../../svg/${ this.props.file }`), true)
request.onreadystatechange = () => {
if (request.readyState === 4 && request.status==200) {
this.setState({svg: request.response})
}
}
request.send()
},
render() {
return <span className={this.props.className}
dangerouslySetInnerHTML={{__html: this.state.svg }} />
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment