Last active
February 9, 2021 22:52
-
-
Save 3200pro/3c15fd4f9a95529071c6973a452bc44f to your computer and use it in GitHub Desktop.
Figure Ternary Setup For Gatsby & Sanity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import { getFluidGatsbyImage } from 'gatsby-source-sanity' | |
import Img from 'gatsby-image' | |
import { buildImageObj } from '../../lib/helpers' | |
import { imageUrlFor } from '../../lib/image-url' | |
import clientConfig from '../../../client-config' | |
function Figure(props) { | |
const data = props | |
return ( | |
<figure> | |
{data.disableGatsbyImage !== true ? ( | |
<Img | |
fluid={ | |
data.asset | |
? getFluidGatsbyImage( | |
data.asset._ref, | |
{ maxWidth: 800 }, | |
clientConfig.sanity | |
) | |
: null | |
} | |
alt={data.alt} | |
loading="lazy" | |
/> | |
) : ( | |
<img src={imageUrlFor(buildImageObj(data)).url()} alt={data.alt} /> | |
)} | |
<figcaption>{data.caption}</figcaption> | |
</figure> | |
) | |
} | |
export default Figure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment