Skip to content

Need help to use GatsbyImage in react-photo-album #76

Answered by igordanchenko
geohuz asked this question in Q&A
Discussion options

You must be logged in to vote

Since you are using a custom render function in this case, you can pass any string as photo src, as long as you are able to lookup the photo object based on that string inside the render function.

For example, you can pass an index of the photo in the array.

const photos = images.nodes.map(
    (
        {
            childImageSharp: {
                gatsbyImageData: { width, height },
            },
        },
        index
    ) => ({
        src: `${index}`,
        width,
        height,
    })
);

and then lookup Gatsby image in the renderPhoto:

const image = images.nodes[+photo.src];
return <GatsbyImage key={image.name} alt={image.name} image={image.childImageSharp.gatsbyImageData} />

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@geohuz
Comment options

@geohuz
Comment options

@igordanchenko
Comment options

@geohuz
Comment options

Answer selected by igordanchenko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants