Skip to content

Swap image source with gatsby-image #11298

@wmcheung

Description

@wmcheung

A quick question, is it possible to swap images using gatsby-image?

The query I'm using in my Image component is:

query {
              allImageSharp {
                edges {
                  node {
                    ... on ImageSharp {
                      fluid(maxWidth: 1250) {
                        ...GatsbyImageSharpFluid,
                        originalName
                      }
                    }
                  }
                }
              }
            }

This looks for the file name in my Image component which is sent to the gatbsy-image.

const image = data.allImageSharp.edges.find( (e) => {
              if (e.node.fluid.originalName === this.props.src) {
                return e.node;
              }
            });

<Img fluid={image.node.fluid} />

What should happen is if I create an onClick and I choose to change it into image-2.png, it should show the new image. The image gets replaced but it remains to show the blurred version.

Here is a GIF of what is happening https://cl.ly/c2729110e408

Much appreciated for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions