Material-ui: Equivalent of onerror in Avatar component

Created on 24 Apr 2018  路  4Comments  路  Source: mui-org/material-ui

<img src="someImage.png" onerror="someErrorFunction(this);"/>

Just curious what's the equivalent of onerror for Avatar component. I looked up the documentation, couldn't find anything useful. Avatar Documentation

duplicate

Most helpful comment

for anyone else looking for an example for this,
you can now do:

             <Avatar
                src={imgSrc}
                imgProps={{ onError: (e) => { e.target.src = defaultImage(); } }}
              />

to use another img if it errors out on load

All 4 comments

@temurih It's a duplicate of #5257.
We have added a test case for it on the v1-beta branch:
https://github.com/mui-org/material-ui/blob/3e4854b39b17511d9b312071ca93061eeb503f5d/packages/material-ui/src/Avatar/Avatar.test.js#L51-L55

I am not sure what that means, but I guess I can implement this of my own.

@temurih It means that the onError property can be used on v1-beta. It also means that v0.x is no longer maintained.

for anyone else looking for an example for this,
you can now do:

             <Avatar
                src={imgSrc}
                imgProps={{ onError: (e) => { e.target.src = defaultImage(); } }}
              />

to use another img if it errors out on load

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sys13 picture sys13  路  3Comments

revskill10 picture revskill10  路  3Comments

FranBran picture FranBran  路  3Comments

pola88 picture pola88  路  3Comments

chris-hinds picture chris-hinds  路  3Comments