Update 2016-05-27
As with React v15, SVG support in React (close to?) Is 100% parity with current browser support for SVG ( source ), you just need to apply some syntax conversions to make it compatible with JSX, as you should already do for HTML ( class β className , style="color: purple" β style={{color: 'purple'}} ). For any attribute separated by names (colon), for example. xlink:href , remove : and head the second part of the attribute, for example. xlinkHref . Here's an example svg with <defs> , <use> and inline styles:
function SvgWithXlink (props) { return ( <svg width="100%" height="100%" xmlns="http://www.w3.org/2000/svg" xmlnsXlink="http://www.w3.org/1999/xlink" > <style> { `.classA { fill:${props.fill} }` } </style> <defs> <g id="Port"> <circle style={{fill:'inherit'}} r="10"/> </g> </defs> <text y="15">black</text> <use x="70" y="10" xlinkHref="#Port" /> <text y="35">{ props.fill }</text> <use x="70" y="30" xlinkHref="#Port" className="classA"/> <text y="55">blue</text> <use x="0" y="50" xlinkHref="#Port" style={{fill:'blue'}}/> </svg> ); }
Working demo codepen
See the list of supported SVG attributes for more information on specific support . And heres (now closed) a GitHub issue that tracked support for naming SVG attributes.
Previous answer
You can make SVG embedding easy without using dangerouslySetInnerHTML by simply separating the namespace attributes. For example, this works:
render: function() { return ( <svg viewBox="0 0 120 120"> <circle cx="60" cy="60" r="50"/> </svg> ); }
At this point, you might consider adding props, such as fill , or what else might be useful for customization.
Andrew Patton Jun 01 '15 at 17:40 2015-06-01 17:40
source share