React Package Documentation
Updated at: November 1, 2025
Build beautiful interfaces with @favicolor/react components
Features
The @favicolor/react package offers many advanced features:
Flexible sizes
Accepts any size between 32 and 128 pixels, automatically rounded to optimal API size
Retina/HiDPI detection
Automatically loads 2x images on high-resolution displays (Retina, 4K, etc.)
Dynamic DPI detection
Automatically recalculates image when window is moved between displays with different resolutions
Elegant fallback
Displays a default globe icon if favicon is not found
Smart cache
Colors are cached, image URLs are dynamically calculated based on DPR
Light/dark themes
Native support for both themes with optimized colors
Strict TypeScript
Strict typing for all props and interfaces
SSR-safe
Compatible with Next.js and other SSR frameworks
Adaptive inline
FavicolorInlineIcon automatically adapts to text size
Installation
Install the package via your preferred package manager:
npm install @favicolor/react
Configuration
Wrap your application with FavicolorProvider to configure API access:
1import { FavicolorProvider } from '@favicolor/react';23function App() {4return (5<FavicolorProvider6config={{7apiUrl: 'https://api.favicolor.com', // Optionnel8apiKey: process.env.NEXT_PUBLIC_FAVICOLOR_API_KEY, // Pour localhost9appId: process.env.NEXT_PUBLIC_FAVICOLOR_APP_ID, // Pour production10defaultTheme: 'dark', // 'light' ou 'dark'11defaultSize: 64, // Taille entre 32 et 128 pixels12enableRetina: true, // Active la détection Retina (défaut: true)13}}14>15<YourApp />16</FavicolorProvider>17);18}
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
apiUrl | string | https://api.favicolor.com | Favicolor API URL |
apiKey | string | undefined | API key for requests from localhost (development) |
appId | string | undefined | Application ID for requests from registered domains (production) |
defaultTheme | 'light' | 'dark' | 'dark' | Default theme for all components |
defaultSize | number | 64 | Default icon size in pixels (between 32 and 128) |
enableRetina | boolean | true | Enables automatic detection of Retina/HiDPI displays |
Authentication
The package automatically handles authentication based on your environment:
- apiKey: Used automatically for requests from localhost (development)
- appId: Used for requests from registered domains (production)
Components
FavicolorIcon
Displays a favicon in a squircle container with colors automatically extracted by the API.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
url | string | required | Full URL or domain name |
size | number | optional | Image size in pixels (between 32 and 128). Automatically rounded to optimal API size |
theme | 'light' | 'dark' | optional | Color theme |
className | string | optional | Additional CSS classes |
fallback | ReactNode | optional | Custom fallback component |
shape | 'circle' | 'square' | 'squircle' | 'custom' | 'auto' | optional | Container shape |
Code Example
1import { FavicolorIcon } from '@favicolor/react';23function MyComponent() {4return (5<FavicolorIcon6url="https://github.com"7size={64}8theme="dark"9className="hover:scale-110 transition-transform"10/>11);12}
FavicolorInlineIcon
Inline icon with adaptive em sizing to naturally integrate with text.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
url | string | required | Full URL or domain name |
theme | 'light' | 'dark' | optional | Color theme |
className | string | optional | Additional CSS classes |
style | CSSProperties | optional | Inline CSS styles (e.g., width: '1.5em') |
Visitez GitHub
Code Example
1import { FavicolorInlineIcon } from '@favicolor/react';23function MyText() {4return (5<p className="text-lg">6Visitez <FavicolorInlineIcon url="github.com" /> GitHub7</p>8);9}
FavicolorLink
Link with automatic inline favicon.
Props
| Prop | Type | Required | Description |
|---|---|---|---|
href | string | required | Destination URL |
children | ReactNode | required | Link content |
iconPosition | 'left' | 'right' | optional | Icon position |
showIcon | boolean | optional | Display icon |
className | string | optional | Additional CSS classes |
iconClassName | string | optional | Additional CSS classes |
iconStyle | CSSProperties | optional | Inline CSS styles (e.g., width: '1.5em') |
target | string | optional | Link target attribute |
rel | string | optional | Link rel attribute |
Code Example
1import { FavicolorLink } from '@favicolor/react';23function MyLinks() {4return (5<div>6<FavicolorLink href="https://github.com">7Visitez GitHub8</FavicolorLink>910<FavicolorLink11href="https://google.com"12iconPosition="right"13className="text-blue-500 hover:underline"14>15Rechercher16</FavicolorLink>17</div>18);19}
Hook
useFavicolor
React hook to access Favicolor configuration from context.
Usage Example
1import { useFavicolor } from '@favicolor/react';23function MyComponent() {4const config = useFavicolor();5console.log(config.apiUrl); // 'https://api.favicolor.com'6console.log(config.defaultTheme); // 'dark'7}
The hook returns the complete FavicolorProvider configuration, allowing you to access all configured options.
Retina/HiDPI Optimization
How does it work?
1. Automatic detection
The component detects the screen DPR (window.devicePixelRatio)
2. Smart calculation
API size is automatically calculated: displaySize × min(DPR, 2)
3. Optimal rounding
Rounds up to nearest API size (32, 64, 96, 128) to avoid upscaling
4. 2x cap
DPR is capped at 2x maximum to optimize bandwidth
Examples
<FavicolorIcon url="github.com" size={64} />// → Charge une image 64×64 pixels
Disable Retina detection
If you want to disable Retina detection (e.g., to save bandwidth), pass enableRetina: false in the Provider configuration.
1<FavicolorProvider2config={{3enableRetina: false, // Désactive la détection Retina4}}5>6<App />7</FavicolorProvider>
Dynamic screen change detection
The component automatically listens for resolution changes via matchMedia. When you move the window from a standard display to a Retina display (or vice-versa), the image is automatically recalculated and reloaded.