Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gatsby-dynamic-image

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gatsby-dynamic-image

A React component wrapping gatsby-image

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

gatsby-dynamic-image

A React component that given a Gatsby File node will either render a gatsby-image component or a native img element. This is useful for cases where you don't know whether or not an image has been processed by gatsby-transformer-sharp (such as when iterating over a collection which contains references to images of varying formats).

Usage

  • Install the package from npm:
npm install --save gatsby-dynamic-image
  • Import the component and use it in place of any existing gatsby-image instance or img element. The following example assumes a collection of Markdown documents processed with gatsby-transformer-remark and gatsby-remark-images containing image paths in frontmatter:
import Image from 'gatsby-dynamic-image';
import React from 'react';

export default ({ data }) => (
  <React.Fragment>
    <h1>My images</h1>
    {data.allMarkdownRemark.edges.map(node => (
      <Image node={node.frontmatter.image} />
    ))}
    <Image node={data} />
  </React.Fragment>
);

export const query = graphql`
  query {
    allMarkdownRemark {
      edges {
        node {
          frontmatter {
            image {
              publicURL
              childImageSharp {
                fluid(maxWidth: 980) {
                  ...GatsbyImageSharpFluid
                }
              }
            }
          }
        }
      }
    }
  }
`;

FAQs

Package last updated on 24 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc