How to edit svg

August 13, 2024

Previous

In Next.js, you can import a svg file and show it by using an <Image /> tag without other package

import exampleSvg from 'example.svg' <Image src={exampleSvg} {...props} />

Component

First, you install @svgr/webpack package

npm install @svgr/webpack

And then, you can import a svg and use it as a component

import ExampleSvg from 'example.svg' <ExampleSvg />

Now

While import the svg file, you can execute it as a function, and it will return dom message

import ExampleSvg from 'example.svg' const svgChildren = ExampleSvg()

And then, you can edit it with React function.

React.cloneElement(svgChildren, {...props}, null)

In this way, you can edit the dom of svg.