next-react-svg

Transform your svg image to a React component.

Usage no npm install needed!

<script type="module">
  import nextReactSvg from 'https://cdn.skypack.dev/next-react-svg';
</script>

README

Next React Svg

npm version

Transform your svg image to a React component.

Features

  • Svg properties
  • React props and events

Installation

yarn add next-react-svg -E

Usage

Create a next.config.js in your project and pass an include to define the svg folder localization.

const withReactSvg = require('next-react-svg')
const path = require('path')

module.exports = withReactSvg({
  include: path.resolve(__dirname, 'src/assets/svg'),
  webpack(config, options) {
    return config
  }
})
import Logo from 'assets/svg/Logo.svg';

export default () => (
  <Logo />
);

Typescript

For those using Typescript, make sure to to add the code below into your next-env.d.ts file.

/// <reference types="next-react-svg" />