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.

Add onError to img element

See original GitHub issue

Gravatar 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:open
  • Created 7 years ago
  • Reactions:4
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
zhubercommented, Jul 12, 2018

I have created a PR that provides this functionality: https://github.com/KyleAMathews/react-gravatar/pull/146

1reaction
cjkecommented, Jan 24, 2017

Groovy I will get a PR together shortly.

Read more comments on GitHub >

github_iconTop 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 >

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