Skip to content

Instantly share code, notes, and snippets.

@3200pro
Last active February 9, 2021 22:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3200pro/3c15fd4f9a95529071c6973a452bc44f to your computer and use it in GitHub Desktop.
Save 3200pro/3c15fd4f9a95529071c6973a452bc44f to your computer and use it in GitHub Desktop.
Figure Ternary Setup For Gatsby & Sanity
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