@roeefl/use-dynamic-svg-import
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

use-dynamic-svg-import

A small react hook to allow dynamically importing SVG files directly into jsx/tsx files\

credits

Many thanks to (@junwen-k)[https://stackoverflow.com/users/11125492/junwen-k] for this See (original thread)[https://stackoverflow.com/a/61472427/6643053]

how to add to repo

pnpm:
pnpm i --save-dev @roeefl/use-dynamic-svg-import

npm:
npm i --save-dev @roeefl/use-dynamic-svg-import

how to use in an example Icon fuctional component

import { useDynamicSvgImport } from '@roeefl/use-dynamic-svg-import';

export function Icon({ name }: { name: string }) {
  const { loading, SvgIcon } = useDynamicSvgImport(name);

  if (loading) {
    // ...
  }

  return <SvgIcon width={...} height={...} color={...} className={...} />
}

Package Sidebar

Install

npm i @roeefl/use-dynamic-svg-import

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

18.6 kB

Total Files

8

Last publish

Collaborators

  • roeefl