Skip to content

Commit

Permalink
fix props spread
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Nov 25, 2024
1 parent f706939 commit 2494ca3
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/mui-material/src/Avatar/Avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,23 @@ const Avatar = React.forwardRef(function Avatar(inProps, ref) {

let children = null;

// Use a hook instead of onError on the img element to support server-side rendering.
const loaded = useLoaded({ ...imgProps, src, srcSet });
const hasImg = src || srcSet;
const hasImgNotFailing = hasImg && loaded !== 'error';

const ownerState = {
...props,
colorDefault: !hasImgNotFailing,
component,
variant,
};

// Use a hook instead of onError on the img element to support server-side rendering.
const loaded = useLoaded({
...imgProps,
...(typeof slotProps.img === 'function' ? slotProps.img(ownerState) : slotProps.img),
src,
srcSet,
});
const hasImg = src || srcSet;
const hasImgNotFailing = hasImg && loaded !== 'error';

ownerState.colorDefault = !hasImgNotFailing;
// This issue explains why this is required: https://github.com/mui/material-ui/issues/42184
delete ownerState.ownerState;

Expand Down

0 comments on commit 2494ca3

Please sign in to comment.