Created
April 14, 2015 18:42
-
-
Save averyvery/ee758c0b0e6fda74cdc7 to your computer and use it in GitHub Desktop.
svg.jsx
This file contains hidden or 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
// 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