'Set a default value for Image src in next.js

i'm trying to set a default value for image src in the Image component in next.js. i can't find any option to do that, for case the server response with status code 400. corrently i'm getting in the console text like:

The requested resource isn't a valid image for <url for invalid image here> received inode/x-empty

i want to return a default image in case the requested image doesn't found. thanks in advece!

i tried to build a component like:

const CustomImage = ({
                         src = placeholder,
                         alt = "alt",
                         size = "125px",
                         cycle = false
                     }) => {
    return <Image
        src={src}
        width={size}
        height={size}
        alt={alt}
        quality={"100"}
        layout={"fixed"}
        style={{
            borderRadius:
                cycle ? "50%" : ".15em"
        }}
    />
}

and it doesn't help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source