yarn add svg-to-component
const Svg2Component = require('svg-to-component')
// Generate React component from SVG string
new Svg2Component()
//...........svg string, component name
.fromString('<svg ...', 'MyIcon')
.toReactComponent()
// export default function MyIcon(props) {
// return <svg ...>
// }
// You can also directly generate component from an SVG file
new Svg2Component()
.fromFileSync('./my-icon.svg', 'optional-component-name')
.toVueComponent()
const svg2component = new Svg2Component()
SVG string.
Could be either of:
kebab-case
or PascalCase
.Return a Promise.
Path to SVG file.
Component name.
Like .fromFile
but sync and return this
Return a string which represents a React component.
Type: boolean
Default: true
Return a string which represents a Vue component.
Type: boolean
Default: true
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
Author: egoist
GitHub: https://github.com/egoist/svg-to-component
#vuejs #javascript #vue #react