safe-gatsby-image-plugin
v1.0.8
Published
Safe React Image component that doesn't break when some inputs are undefined but renders a placeholder image
Downloads
2
Readme
Fail-safe wrapper around Gatsby-Image component
How it works
- If the transformed localFile cannot be found, the original image is used.
- If the passed image is
null|undefined
, a placeholder image will be used.
Setup
1. Install
npm i safe-gatsby-image-plugin
2. Usage example
import { Image } from 'safe-gatsby-image-plugin';
// Example of of what a typical image object returned by Gatsby looks like
const imageDataObj = {
localFile: {
alt_text,
source_url,
childImageSharp: {
fluid: {
...
}
}
}
}
<Image data={imageDataObj} className='image-class' style={{marginTop: 10}} />