mango-ui-v3/components/ImageWithFallback.tsx

20 lines
369 B
TypeScript

import React, { useState } from 'react'
import Image from 'next/image'
const ImageWithFallback = (props) => {
const { src, fallbackSrc, ...rest } = props
const [imgSrc, setImgSrc] = useState(src)
return (
<Image
{...rest}
src={imgSrc}
onError={() => {
setImgSrc(fallbackSrc)
}}
/>
)
}
export default ImageWithFallback