Created
October 31, 2016 05:36
-
-
Save kevinweber/3c519c32db6c976e9cbb5565dc3822f1 to your computer and use it in GitHub Desktop.
Helper: Convert React component (SVG element) to base64 encoded URL. Useful for adding a background image.
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
import ReactDOMServer from 'react-dom/server'; | |
export function encodeSvg(reactElement) { | |
return 'data:image/svg+xml,' + escape(ReactDOMServer.renderToStaticMarkup((reactElement))); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment