I’ve svg jsx components that i want as string so i can copy it. on the website i’m working on, i’ve provided two options to copy the svg element. one i achieved by using renderToString
function from react-dom/server
, that gives me svg string, and other one i want as jsx component string,
the component
const SvgComponent1 = (props) => (
<svg
xmlns="http://www.w3.org/2000/svg"
width={100}
height={100}
fill="none"
{...props}
>
<path
fill="#D9D9D9"
stroke="#000"
strokeWidth={5}
d="M2.5 2.5h95v95h-95z"
/>
</svg>
)
renderToString function result
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" fill="none"><path fill="#D9D9D9" stroke="#000" stroke-width="5" d="M2.5 2.5h95v95h-95z"></path></svg>
is this possible to convert this svg string back to the jsx string, similar to svgr playground at runtime? do i have to store the string version with the jsx code, not possible at runtime? i have many svgs.