Overview
A lightweight runtime layer over the Mastericons CDN — built for modern React apps.
No bundle bloat
Icons load from the Mastericons CDN at runtime. Your app ships a tiny package — not 200K+ SVG files.
200K+ icons
Lucide, Tabler, Phosphor, Heroicons, and 50+ more libraries — one consistent API.
On-demand fetch
Only icons you render are fetched. In-flight requests are deduplicated and cached in memory.
Domain-locked keys
Publishable API keys are safe in the browser. Each key is restricted to origins you configure in your account.
Styled output
Set size, color, and stroke width as props. The package applies styles to the fetched SVG for you.
Accessible by default
Pass title or aria-label for screen readers. Icons are decorative when neither is provided.
Installation
Install the package and ensure React 18+ is available.
Peer dependencies: react and react-dom>= 18.
Quick start
Wrap your app once with your API key, then render icons by ID.
API keys
Pro and Lifetime subscribers can create publishable, domain-locked API keys for the React library.
Keys are safe to use in the browser. Each key is restricted to the origins you configure — requests from other domains are rejected.
Create API keySet the key once — you never repeat it on individual icons. Pick whichever fits your setup:
- Set
NEXT_PUBLIC_MASTERICONS_API_KEY— the provider reads it automatically (recommended for Next.js). - Call
configureMastericons({ apiKey })once at your entry point (recommended for Vite / non-React). - Pass
apiKeydirectly toMastericonsProvider(overrides the others).
Icon IDs
Reference icons by library and slug. Browse the full catalogue on Mastericons.
Next.js & SSR
Icon and MastericonsProvider are client components. Add the provider in a client boundary at your app root.
Fetches use the authenticated API at /api/v1/icons/rawwith your API key. In the browser, the Origin header is validated against your key's allowlist.
API reference
Exports from @mastericons/react.
MastericonsProvider
Supplies API key and fetch configuration to all icons in the subtree. Wrap your app or any section that renders icons.
Icon
Renders a single icon by ID. Shows fallback while loading or when fetch fails.
useIconSvg
Lower-level hook when you need the styled SVG string instead of the Icon component.
Returns { svg, loading, error }. Also exports useMastericonsConfig() to read the active provider config.
Licensing
@mastericons/react is MIT-licensed and ships code only — no SVG assets are bundled. Icons are loaded from the Mastericons CDN and originate from many upstream libraries with their own licenses. See the monorepo NOTICE for attribution details.
Best practices
Tips for production React apps.
Wrap once with MastericonsProvider
Place the provider at your app root with your publishable API key. All Icon and useIconSvg calls share the same config and fetch implementation.
Add your origins when creating a key
Include every domain where your app runs — e.g. http://localhost:3000 for local dev and https://myapp.com for production. Requests from unlisted origins are rejected.
Use colon or hyphen IDs
Both lucide:home and lucide-home work. Copy IDs from the browse page or use the library:slug format familiar from Iconify.
Provide a fallback for loading states
The Icon component shows fallback while fetching or on error. Use a skeleton or placeholder to avoid layout shift in lists and nav bars.
Prefer title or aria-label for meaning
Icons without a title or aria-label are marked aria-hidden. Add one when the icon conveys information, not just decoration.
Use @mastericons/core for custom UIs
Need fetchIconSvg or URL builders outside React? Import from @mastericons/core — the React package wraps the same primitives.