# react-inlinesvg
[](https://www.npmjs.com/package/react-inlinesvg) [](https://github.com/gilbarbara/react-inlinesvg/actions/workflows/ci.yml) [](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg) [](https://sonarcloud.io/summary/new_code?id=gilbarbara_react-inlinesvg)
Load inline, local, or remote SVGs in your React components.
View the [demo](https://codesandbox.io/s/github/gilbarbara/react-inlinesvg/tree/main/demo)
## Highlights
- 🏖 **Easy to use:** Just set the `src`
- 🛠 **Flexible:** Personalize the options to fit your needs
- ⚡️ **Smart:** Async requests will be cached.
- 🚀 **SSR:** Safe for server-side rendering
## Usage
```sh
npm i react-inlinesvg
```
And import it into your code:
```tsx
import SVG from 'react-inlinesvg';
export default function App() {
return (
);
}
```
## Props
**src** {string} - **required**.
The SVG to load. It accepts:
- A URL or path to an SVG file (absolute or relative, including from a bundler import)
- A data URI (base64 or URL-encoded)
- A raw SVG string
**baseURL** {string}
A URL to prepend to `url()` references inside the SVG when using `uniquifyIDs`. Required if your page uses an HTML `` tag.
**children** {ReactNode}
The fallback content in case of a fetch error or unsupported browser.
```
```
**cacheRequests** {boolean} ▶︎ `true`
Cache remote SVGs in memory. When used with the [CacheProvider](#caching), requests are also persisted in the browser cache.
**description** {string}
A description for your SVG. It will override an existing `` tag.
**fetchOptions** {RequestInit}
Custom options for the [request](https://developer.mozilla.org/en-US/docs/Web/API/Request/Request).
**innerRef** {React.Ref\}
Set a ref on the SVG element.
>The SVG is processed and parsed so the ref won't be set on the initial render.
You can use the `onLoad` callback to get and use the ref instead.
**loader** {node}
A component to be shown while the SVG is loading.
**onError** {function}
A callback to be invoked if loading the SVG fails.
This will receive a single argument with:
- a `FetchError` with:
```typescript
{
message: string;
type: string;
errno: string;
code: string;
}
```
- or an `Error` for issues like missing `src`, unsupported browser, or invalid SVG content.
**onLoad** {function}.
A callback to be invoked upon successful load.
This will receive 2 arguments: the `src` prop and an `isCached` boolean
**preProcessor** {function}
A function to pre-process the SVG string before parsing. Receives the SVG string and must return a string.
**title** {string | null}
A title for your SVG. It will override an existing `` tag.
If `null` is passed, the `` tag will be removed.
**uniqueHash** {string} ▶︎ a random 8 characters string `[A-Za-z0-9]`
A string to use with `uniquifyIDs`.
**uniquifyIDs** {boolean} ▶︎ `false`
Create unique IDs for each icon.
> Any additional props will be passed down to the SVG element.
### Example
```tsx