question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow custom props to Gatsby-Image component

See original GitHub issue

Summary

Custom props should be allowed to be passed to the root tag of a Gatsby Image component.

Basic example

import Image from 'gatsby-image'

<Image customProp={1} />
<Image {...customProps} />

In this example, customProp and customProps should be passed to the root element of the Image component.

Motivation

I’m sure there are several use cases where custom props would be useful. A good example is for flip animations. React-flip-toolkit, requires custom props to be passed to the root element of a React component. Without the ability to pass custom props, flip animations are not possible.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

5reactions
wardpeetcommented, Jul 3, 2020

Thank you for opening this issue.

Gatsby-image was created so people can have an easy way to setup images from Gatsby. If we enable custom props, this could lead to bad a11y, weird bugs and more. For these reasons, I’ll close this PR. We hope to have a better gatsby-image component in the near future that can be used more granular and fixes your issue.

2reactions
oolothcommented, Jul 6, 2020

@polarathene Thanks!

Passing props/attributes to a wrapper element is a workable solution for now (I didn’t realize how complicated the pass-through request would turn out to be).

It would be awkward as a permanent approach, but @wardpeet mentioned there’s a broader solution in the works, so I’m looking forward to that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Gatsby Image plugin
The Gatsby Image plugin includes two components to display responsive images on ... The following props can be passed to both GatsbyImage and...
Read more >
How to pass a path of image as a prop in Gatsby in Gatsby ...
There are a few technical restrictions to the way you can pass props into StaticImage . Most importantly, you can't use any of...
Read more >
React Hooks Handbook - Gatsby Plugin Image - Design+Code
The plugins we just installed include two different components that we can use to render images. One is called StaticImage , and one...
Read more >
Daily Dose of Gatsby Episode 5 - YouTube
In this episode, you will learn about the Gatsby Image component and how it can be used to better process and display images...
Read more >
Custom sizes attribute with gatsby-image (by a Gatsby newbie)
I thought it could be set using an attribute/prop on the <Img /> component, but that didn't work. Instead, it turned out I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found