Last active
July 25, 2020 00:23
-
-
Save jamiejohnsonkc/fea04c1b0d9c05fde9ff93b3fd53b594 to your computer and use it in GitHub Desktop.
custom gatsby fluid image hook comp & implementation
This file contains hidden or 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
| /** @jsx jsx */ | |
| import { jsx } from "theme-ui" | |
| import React from "react" | |
| import { graphql, useStaticQuery } from "gatsby" | |
| import styled from "@emotion/styled" | |
| import BackgroundImage from "gatsby-background-image" | |
| import useBackgroundImage from "./useBackgroundImage" | |
| const BackgroundImageContainer = ({ className }) => { | |
| const data = useBackgroundImage() | |
| return ( | |
| <div> | |
| <BackgroundImage | |
| Tag="section" | |
| className={className} | |
| fluid={data} | |
| backgroundColor={`#040e18`} | |
| > | |
| <h1>From the comp</h1> | |
| </BackgroundImage> | |
| </div> | |
| ) | |
| } | |
| export default BackgroundImageContainer |
This file contains hidden or 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
| |
This file contains hidden or 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
| /** @jsx jsx */ | |
| import { jsx } from "theme-ui" | |
| import React from "react" | |
| import { graphql, useStaticQuery } from "gatsby" | |
| import styled from "@emotion/styled" | |
| const useBackgroundImage = () => { | |
| const data = useStaticQuery(graphql` | |
| query FluidBackgroundImage { | |
| file(relativePath: { eq: "gatsby-astronaut.png" }) { | |
| childImageSharp { | |
| fluid { | |
| base64 | |
| aspectRatio | |
| src | |
| srcSet | |
| sizes | |
| } | |
| } | |
| } | |
| } | |
| `) | |
| return data.file.childImageSharp.fluid | |
| } | |
| console.log(useBackgroundImage) | |
| export default useBackgroundImage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment