Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@svgr/core

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@svgr/core

Transform SVG into React Components.

  • 6.4.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
8.3M
increased by5.73%
Maintainers
1
Weekly downloads
 
Created

What is @svgr/core?

The @svgr/core package is a tool that transforms SVG images into React components. This allows developers to easily import and use SVG files as React components in their projects, enhancing the integration of vector graphics with React applications.

What are @svgr/core's main functionalities?

SVG to React Component Transformation

This feature allows the conversion of SVG markup into a React component. The transform function takes the SVG code, optional configuration options, and settings for the component name, then outputs JSX code.

import { transform } from '@svgr/core';

const svgCode = '<svg><path d="M10 10 H 90 V 90 H 10 L 10 10"/></svg>';
const jsxCode = transform(svgCode, { icon: true }, { componentName: 'MyIcon' });
console.log(jsxCode);

Custom Template Usage

This feature allows developers to use a custom template for transforming SVG into a React component. It provides flexibility in how the resulting JSX is structured and exported.

import { transform } from '@svgr/core';

const svgCode = '<svg><path d="M10 10 H 90 V 90 H 10 L 10 10"/></svg>';
const customTemplate = ({ template }, opts, { imports, componentName, props, jsx, exports }) => template.ast`
  import * as React from 'react';
  const \
${componentName} = (props) => <svg {...props}>${jsx}</svg>;
  export default ${componentName};
`;
const jsxCode = transform(svgCode, { template: customTemplate }, { componentName: 'MyCustomIcon' });
console.log(jsxCode);

Other packages similar to @svgr/core

Keywords

FAQs

Package last updated on 01 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc