Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/sairion/svg-inline-react

Inline svg wrapper component for React
https://github.com/sairion/svg-inline-react

inline-svg react svg

Last synced: 7 days ago
JSON representation

Inline svg wrapper component for React

Awesome Lists containing this project

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"](https://css-tricks.com/using-svg/) for further detail. However, I recommended to use static svg transformed as React component, since React now supports svg properly.

## note for 1.x.x user: transpiling is discontinued

I removed `dist` and `es` and made `lib` (which is ES2015 source) default, and there are several reason for it. For now use of ES2015 (and modules) is widespread, there are many tools supporting it (i.e. Webpack 2, Rollup), and you will use them anyway – if you are using React/etc. If you want to stay in CommonJS land, please specify deps as `1.x.x`. i.e) `svg-inline-react: 1.x.x`

## Usage

You can use [`svg-inline-loader`](https://github.com/sairion/svg-inline-loader) with [Webpack](https://webpack.github.io) to inline SVG.

Example:

```jsx
import InlineSVG from 'svg-inline-react';

// Use with loader

// Use without loader
const svgSource = `



`;

```

### prop `src` : string

valid SVG element string.

### prop `element` : string

You can change element where svg included using `element` prop, default is ``. 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. Also, the prop will be ignored on server side rendering environment.

## Notes

[inspired by](https://gist.github.com/MoOx/1eb30eac43b2114de73a)