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 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-fallback-img

v1.0.0

Published

Gestion intelligente des erreurs d'images pour vos applications React : bascule sur une image de secours et gère les états de chargement

Readme

React-Fallback-Img

Gestion intelligente des erreurs d'images pour vos applications React.

npm License

🌟 Présentation

React-Fallback-Img est une bibliothèque légère conçue pour améliorer l'expérience utilisateur (UX) en gérant élégamment les échecs de chargement d'images. Au lieu d'afficher l'icône de navigateur par défaut pour les liens brisés, cette lib permet de basculer sur une image de secours prédéfinie tout en gérant les états de chargement.

🚀 Installation

# Via npm
npm install react-fallback-img

# Via yarn
yarn add react-fallback-img

react et react-dom (>= 18) sont des peer dependencies : ils doivent déjà être présents dans votre projet.

🛠️ Utilisation Rapide

Remplacez simplement vos balises <img /> par SmartImage.

import { SmartImage } from 'react-fallback-img';
import 'react-fallback-img/dist/styles.css'; // styles de transition (optionnel)

const MyComponent = () => (
  <SmartImage
    src="https://api.monsite.com/photo.jpg"
    fallback="/assets/default-placeholder.png"
    alt="Description de l'image"
    className="img-responsive"
  />
);

⚙️ API & Propriétés (Props)

SmartImage accepte tous les attributs natifs d'une balise <img> (alt, width, loading, style, …) en plus des props suivantes :

| Propriété | Type | Défaut | Description | | -------------- | ---------- | -------- | ------------------------------------------------------ | | src | string | Requis | URL de l'image principale. | | fallback | string | Requis | URL de l'image si la source principale échoue. | | loader | ReactNode| null | Élément affiché pendant le chargement (ex : Skeleton). | | fadeDuration | number | 300 | Durée de l'animation d'apparition en millisecondes. | | onImageError | function | — | Fonction appelée si l'image principale ne charge pas. |

Exemple complet

<SmartImage
  src={user.avatarUrl}
  fallback="/assets/avatar-default.png"
  alt={user.name}
  fadeDuration={500}
  loader={<div className="skeleton" />}
  onImageError={(e) => console.warn('Avatar introuvable', e)}
/>

🧠 Fonctionnement Technique

La bibliothèque suit une logique d'état rigoureuse pour garantir la fluidité :

  • Phase 1 : Tentative de chargement de src. L'état est à loading.
  • Phase 2 (Succès) : L'image est affichée avec une transition d'opacité.
  • Phase 2 (Erreur) : Si une erreur 404/500 survient, l'événement onError est intercepté. La source bascule sur fallback.
  • Sécurité : Un drapeau interne empêche les boucles infinies si le fallback est lui-même introuvable.

Astuce : Vous pouvez cibler la classe CSS .rfi-image pour personnaliser les transitions globales de votre application. La durée du fondu est exposée via la variable CSS --rfi-fade-duration.

L'état courant est également exposé sur l'attribut data-rfi-status (loading | loaded | error) pour faciliter le ciblage CSS et les tests.

🧪 Développement

npm install      # installe les dépendances
npm run build    # compile vers dist/
npm test         # lance la suite de tests (Jest + Testing Library)

📄 Licence

Distribué sous licence MIT. Libre pour usage commercial et personnel.