:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { ReactNode, useEffect, useState } from 'react'
import { aiBlobRenderHandlers } from '../aiBlob'
interface AIImageProps {
src: string
alt: string
className?: string
fallback: ReactNode
}
export function AIImage({ src, alt, className, fallback }: AIImageProps): JSX.Element {
const [failedSrc, setFailedSrc] = useState<string | null>(null)
useEffect(() => setFailedSrc(null), [src])
const handlers = aiBlobRenderHandlers(src, 'image')
if (failedSrc === src) {
return <>{fallback}</>
}
return (
<img
src={src}
alt={alt}
className={className}
data-attr="ai-message-image"
onLoad={handlers.onLoad}
onError={() => {
handlers.onError?.()
setFailedSrc(src)
}}
/>
)
}