Component-Specific

useAvatar

Handle avatar logic including fallbacks, status indicators, and loading states.

import { useAvatar } from "saha-ui"

Uses

Manage avatar display logic: image load/failure, initials fallback, and deterministic background color selection.

Props

NameTypeDescriptionDefault
srcstringImage source URL.-
altstringAlt text used to generate initials."Avatar"
initialsstringOptional custom initials to display; overrides computed initials.-

Returns

NameDescription
showInitialsWhether to show initials (no src or image failed).
bgColorTailwind-like background class chosen deterministically.
initialsTextComputed initials (max 2 characters).
imageLoaded, imageErrorImage load state flags.
handleImageLoad/handleImageErrorHandlers for image events.

Example

const { showInitials, bgColor, initialsText, handleImageLoad } = useAvatar({ src: '/me.jpg', alt: 'John Doe' });

Notes

Background color is derived from text to keep avatars visually varied and consistent across renders.
Saha UI - The Modern React Component Library