npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@budarin/react-svg-icon

v1.0.14

Published

React component for reusable svg icons

Readme

@budarin/react-svg-icon

React компонент для переиспользуемых SVG иконок с автоматической загрузкой и кэшированием.

Установка

npm install @budarin/react-svg-icon
# или
pnpm add @budarin/react-svg-icon
# или
yarn add @budarin/react-svg-icon

Использование

import { SvgIcon } from '@budarin/react-svg-icon';

function App() {
    return (
        <div>
            <SvgIcon url="/icons/home.svg" size={32} className="my-icon" />
            <SvgIcon
                url="https://example.com/icons/user.svg"
                fill="currentColor"
            />
        </div>
    );
}

API

SvgIcon

Компонент для отображения SVG иконок.

Props

| Prop | Тип | Обязательный | По умолчанию | Описание | | ---------- | ------------------------- | ------------ | ------------ | --------------------------- | | url | string | ✅ | - | URL к SVG файлу | | size | number | ❌ | 24 | Размер иконки в пикселях | | ...props | SVGProps<SVGSVGElement> | ❌ | - | Дополнительные SVG атрибуты |

setDefaultIconSize

Функция для изменения размера иконки по умолчанию глобально:

import { setDefaultIconSize } from '@budarin/react-svg-icon';

setDefaultIconSize(32); // изменить размер по умолчанию для всех иконок

setDefaultErrorHandler

Функция для установки глобального обработчика ошибок загрузки иконок:

import { setDefaultErrorHandler } from '@budarin/react-svg-icon';

// Установить один раз в начале приложения (например, в index.tsx или App.tsx)
setDefaultErrorHandler((error, iconUrl) => {
    console.error(`Не удалось загрузить иконку ${iconUrl}:`, error);
    // Можно отправить в систему мониторинга (Sentry, LogRocket и т.д.)
    // Можно показать уведомление пользователю
    // Можно записать в аналитику
});

Преимущества:

  • Настраивается один раз для всего приложения
  • Не нужно добавлять onError к каждой иконке
  • Единая точка для обработки всех ошибок загрузки
  • Удобно для интеграции с системами мониторинга

Примеры

Базовое использование:

<SvgIcon url="/icons/search.svg" />

Кастомным размером:

<SvgIcon url="/icons/heart.svg" size={48} />

Дополнительными атрибутами:

<SvgIcon
    url="/icons/star.svg"
    size={20}
    fill="gold"
    stroke="orange"
    strokeWidth={2}
    className="star-icon"
/>

Особенности

  • Автоматическая загрузка: Иконки загружаются только при первом использовании
  • Кэширование: Загруженные иконки сохраняются в DOM и не загружаются повторно
  • SVG Sprite: Использует SVG sprite для оптимизации производительности
  • Глобальная обработка ошибок: Настройте обработчик один раз для всех иконок с помощью setDefaultErrorHandler
  • currentColor: По умолчанию иконки используют fill="currentColor" для наследования цвета от родителя
  • Доступность: Иконки помечены aria-hidden="true" для улучшения accessibility
  • TypeScript: Полная поддержка TypeScript с типизацией
  • React 18+: Совместимость с React 18 и выше

Требования

  • React >= 18.3.1
  • React DOM >= 18.3.1

Лицензия

MIT