Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mukhindev/react-svg-use-symbol

Easy use of SVG symbols in React
https://github.com/mukhindev/react-svg-use-symbol

icons react svg ui

Last synced: 3 days ago
JSON representation

Easy use of SVG symbols in React

Awesome Lists containing this project

README

        

# @mukhindev/react-svg-use-symbol

Easy use of SVG symbols in React

## Install

```
npm install @mukhindev/react-svg-use-symbol
```

## One-component example

```JavaScript
import { createSVGSymbols } from "@mukhindev/react-svg-use-symbol";

const { Symbols, SVG } = createSVGSymbols({
"two-circles": (




),
box: (



),
});

export default function MyComponent() {
return (







);
}
```

## Icons example

The previous example is intended as a quick demonstration, but is of little use.
`` and `` are useful when there are a lot of reused graphics. For example icons.

```
src
┣━ app
┃ ┗━ App.tsx
┣━ entities
┃ ┗━ MyComponent.tsx
┗━ ui
┗━ Icon
┣━ icons
┃ ┣━ boxIcon.tsx
┃ ┗━ twoCirclesIcon.tsx
┗━ index.ts
```

```JavaScript
// Icon/icons/boxIcon.tsx
export default (



);
```

```JavaScript
// Icon/icons/twoCirclesIcon.tsx
export default (




);
```

```JavaScript
// Icon/index.ts
import { createSVGSymbols } from "@mukhindev/react-svg-use-symbol";
import boxIcon from "./icons/boxIcon";
import twoCirclesIcon from "./icons/twoCirclesIcon";

export const { Symbols: IconSymbols, SVG: Icon } = createSVGSymbols({
"two-circles": twoCirclesIcon,
box: boxIcon,
});
```

```JavaScript
// App.ts
import { IconSymbols } from "src/ui/Icon";

export default function App(props) {
const { children } = props;

return (

{children}


);
}
```

```JavaScript
// MyComponent.ts
import { Icon } from "src/ui/Icon";

export default function MyComponent() {
return (






);
}
```