Components
Image
An enhanced image component that provides error handling, loading states, and fallback functionality. Built on top of the native HTML img element with additional features for better user experience.
Props
- All standard HTML img attributes are supported
onError
: Function - Custom error handler for image loading failuresref
: React.Ref - React ref for accessing the image element
Features
- Automatic error handling
- Fallback on load failure
- Ref forwarding
- Alt text support
- Lazy loading capability
- Native browser caching
Usage Examples
Basic Image
With Error Handling
Responsive Image
With Loading Attributes
With Fallback
Best Practices
-
Image Loading:
- Use appropriate image sizes
- Implement lazy loading
- Provide width and height
- Consider responsive images
-
Error Handling:
- Always provide fallback behavior
- Log errors when needed
- Show user-friendly messages
- Handle network issues
-
Accessibility:
- Use descriptive alt text
- Consider color contrast
- Maintain aspect ratios
- Support screen readers
Performance Tips
- Use appropriate image formats
- Implement lazy loading
- Optimize image sizes
- Use browser caching
- Consider CDN usage
- Implement responsive images
Styling
The component supports all standard image styling including:
- Width and height
- Object fit properties
- Border and border radius
- Margin and padding
- Responsive classes
- Transition effects
Error States
The component handles various error scenarios:
- Network failures
- Invalid image sources
- Loading timeouts
- Missing resources
- CORS issues