mirror of
https://github.com/suitenumerique/meet.git
synced 2026-08-31 04:37:57 +00:00
⚡️(frontend) memoize the Avatar component
The Avatar component is simple and stateless. Memoize it to avoid unnecessary re-renders when its props have not changed.
This commit is contained in:
committed by
aleb_the_flash
parent
acb583b14f
commit
aba5fca655
@@ -49,32 +49,29 @@ export type AvatarProps = React.HTMLAttributes<HTMLDivElement> & {
|
|||||||
bgColor?: string
|
bgColor?: string
|
||||||
} & RecipeVariantProps<typeof avatar>
|
} & RecipeVariantProps<typeof avatar>
|
||||||
|
|
||||||
export const Avatar = ({
|
export const Avatar = React.memo(
|
||||||
name,
|
({ name, bgColor, context, notification, style, ...props }: AvatarProps) => {
|
||||||
bgColor,
|
const initial = name?.trim()?.charAt(0) ?? ''
|
||||||
context,
|
return (
|
||||||
notification,
|
<div
|
||||||
style,
|
style={{
|
||||||
...props
|
backgroundColor: bgColor,
|
||||||
}: AvatarProps) => {
|
...style,
|
||||||
const initial = name?.trim()?.charAt(0) ?? ''
|
}}
|
||||||
return (
|
className={avatar({ context, notification })}
|
||||||
<div
|
{...props}
|
||||||
style={{
|
|
||||||
backgroundColor: bgColor,
|
|
||||||
...style,
|
|
||||||
}}
|
|
||||||
className={avatar({ context, notification })}
|
|
||||||
{...props}
|
|
||||||
>
|
|
||||||
<span
|
|
||||||
aria-hidden="true"
|
|
||||||
className={css({
|
|
||||||
marginTop: '-0.3rem',
|
|
||||||
})}
|
|
||||||
>
|
>
|
||||||
{initial}
|
<span
|
||||||
</span>
|
aria-hidden="true"
|
||||||
</div>
|
className={css({
|
||||||
)
|
marginTop: '-0.3rem',
|
||||||
}
|
})}
|
||||||
|
>
|
||||||
|
{initial}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
Avatar.displayName = 'Avatar'
|
||||||
|
|||||||
Reference in New Issue
Block a user