Allow custom props to Gatsby-Image component
See original GitHub issueSummary
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:
- Created 3 years ago
- Reactions:4
- Comments:8 (8 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.
@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.