JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 14710
  • Score
    100M100P100Q131848F
  • License MIT

Inline SVG wrapper component for React

Package Exports

  • svg-inline-react

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (svg-inline-react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

svg-inline-react: Inline SVG wrapper component for React

This component wraps dangerouslyInnerHTML prop for easier use. Inlining SVG has pros and cons; See "Using SVG" for further detail.

Transpilation needed?

From version 0.2.0, source is written with ES2015, but package default is transpiled source. If you want to use un-transpiled ES2015 source, please import from svg-inline-react/lib.

Usage

You can use svg-inline-loader with Webpack to inline SVG.

Use like:

var InlineSVG = require('svg-inline-react');  // CommonJS
import InlineSVG from 'svg-inline-react/lib'; // ES2015

<InlineSVG src={require("svg-inline!icon.svg")} /> // Use with loader

prop src : string

valid SVG string.

prop element : string

You can change element where svg included using element prop, default is <i />. But self closed tags like img is not allowed, and an error will be thrown from React side.

prop raw : bool (experimental!)

This prop allows your svg file to be rendered directly, without a container element wraps it. This is an experimental feature. Since this feature needs DOMParser svg+xml support, it's only avaialble on >= IE10 and other modern browsers (it checks support before use, so errors won't be thrown though). Also, the prop will be ignored on server side rendering environment.

Notes

This component was initially included with svg-inline-loader, but since it is totally diffrent domain, I moved this component to separate package. Any suggestion or pull request to improve this component would be welcome!

inspired by