SVG to JSX - Convert SVG to React valid SVG (svg2jsx.herokuapp.com)
almost 6 years ago from Raul Dronca, Designer
almost 6 years ago from Raul Dronca, Designer
What is the point to use this ? serious question
JSX doesn't support conventional tag naming.
For example, you may have an SVG that contains:
<path class='class-1' data-name='name-1' d='M-100'/>
JSX wouldn't be able to parse this correctly.
Instead, the correct JSX would be something like:
<path className="class-1' dataName='name-1' d='M-100'/>
(class
becomes className
and data-name
becomes dataName
)
These are just simple examples, but in a large SVG this can be tedious.
Great tool!
Thanks i will look deeper into some documentation to see what i could do with this !
Hey Alessandro,
Besides the stuff Simon already explained it also converts the inline style to attributes or it converts to Javascript objects.
Basically <svg style='fill:red;margin-left:20px;'..
will throw an error in React, but using this tool the output will be like this <svg fill='#f00' style={{marginLeft: 20}}..
which is valid JSX code.
You will find this tool usefull mostly when working with SVG sprites in React.
Super useful, thanks!
Designer News
Where the design community meets.
Designer News is a large, global community of people working or interested in design and technology.
Have feedback?
Login to Comment
You'll need to log in before you can leave a comment.
LoginRegister Today
New accounts can leave comments immediately, and gain full permissions after one week.
Register now