Add onError to img element
See original GitHub issueGravatar accepts a type of “404” - which, if the email is invalid, will return a 404
status code (instead of say retro or wavatar, etc).
Currently though, there is no way to capture that and action via react-gravatar
. It would be nice to be able to pass in a onError prop, and let it be mounted to the img element. This way, a parent component, could catch it, and render a more app relevant default image.
Alternatively, a defaultComponent
prop could be passed, that when a 404 is returned, the react-gravatar
would render it instead.
Happy to PR if this aligns with the projects goals
Issue Analytics
- State:
- Created 7 years ago
- Reactions:4
- Comments:8 (2 by maintainers)
Top Results From Across the Web
onerror Event - W3Schools
The onerror event is triggered if an error occurs while loading an external file (e.g. a document or an image). Tip: When used...
Read more >How does one use the onerror attribute of an img element
The trick is that image loading is asynchronous by nature so the onerror doesn't happen sunchronously, i.e. if you call returnPhotoURL it ...
Read more >Image.onerror - JavaScript: The Definitive Guide, Fourth ...
The onerror property of an Image object specifies an event handler function that is invoked when an error occurs during the loading of...
Read more >Element: error event - Web APIs | MDN
The error event is fired on an Element object when a resource failed to load, or can't be used. For example, if a...
Read more >Replacing <img> with <div> when img.onerror is called
When img.onerror is called, there are several options instead of leaving the broken image: Replace img.src to set a different image ...
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 Free
Top 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
I have created a PR that provides this functionality: https://github.com/KyleAMathews/react-gravatar/pull/146
Groovy I will get a PR together shortly.