react-render-to-json
v0.0.6
Published
hacky way to figure out what is passed to this.props.children in react
Downloads
3,371
Readme
react-render-to-json
module to figure out what is passed to this.props.children in react
install
npm install react-render-to-json --save
usage example
import React from 'react';
import renderToJson from 'react-render-to-json';
class Heart extends React.Component {
render() {
return (
<svg width="24" fill="#00ea00" height="24" viewBox="0 0 24 24">
<g><path d="M12 10.375c0-2.416-1.959-4.375-4.375-4.375s-4.375 1.959-4.375 4.375c0 1.127.159 2.784 1.75 4.375l7 5.25s5.409-3.659 7-5.25 1.75-3.248 1.75-4.375c0-2.416-1.959-4.375-4.375-4.375s-4.375 1.959-4.375 4.375"/></g>
</svg>
);
}
}
console.log(renderToJSon(<Heart />));
{
"name": "Heart",
"attributes": {},
"children": [{
"name": "svg",
"attributes": {
"width": "24",
"fill": "#00ea00",
"height": "24",
"viewBox": "0 0 24 24"
},
"children": [{
"name": "g",
"attributes": {},
"children": [{
"name": "path",
"attributes": {
"d": "M12 10.375c0-2.416-1.959-4.375-4.375-4.375s-4.375 1.959-4.375 4.375c0 1.127.159 2.784 1.75 4.375l7 5.25s5.409-3.659 7-5.25 1.75-3.248 1.75-4.375c0-2.416-1.959-4.375-4.375-4.375s-4.375 1.959-4.375 4.375"
}
}]
}]
}]
}
Used by react-svg-morph
Licence
MIT