Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/sairion/svg-inline-react
- Owner: sairion
- License: mit
- Created: 2015-11-17T07:28:44.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2022-03-02T03:33:29.000Z (almost 3 years ago)
- Last Synced: 2024-12-30T09:32:43.244Z (19 days ago)
- Topics: inline-svg, react, svg
- Language: JavaScript
- Size: 312 KB
- Stars: 131
- Watchers: 4
- Forks: 35
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)