Skip to content

armgit / meet

Public Imported from GitHub
0

Open source video conferencing app powered by LiveKit. Built with Django and React.

⚡️(frontend) memoize the Avatar component

lebaudantoineaba5fca6554c
diff --git a/src/frontend/src/components/Avatar.tsx b/src/frontend/src/components/Avatar.tsx
index 168fa953..6be35f90 100644
--- a/src/frontend/src/components/Avatar.tsx
+++ b/src/frontend/src/components/Avatar.tsx
@@ -49,32 +49,29 @@ export type AvatarProps = React.HTMLAttributes<HTMLDivElement> & {
bgColor?: string
} & RecipeVariantProps<typeof avatar>
-export const Avatar = ({
- name,
- bgColor,
- context,
- notification,
- style,
- ...props
-}: AvatarProps) => {
- const initial = name?.trim()?.charAt(0) ?? ''
- return (
- <div
- style={{
- backgroundColor: bgColor,
- ...style,
- }}
- className={avatar({ context, notification })}
- {...props}
- >
- <span
- aria-hidden="true"
- className={css({
- marginTop: '-0.3rem',
- })}
+export const Avatar = React.memo(
+ ({ name, bgColor, context, notification, style, ...props }: AvatarProps) => {
+ const initial = name?.trim()?.charAt(0) ?? ''
+ return (
+ <div
+ style={{
+ backgroundColor: bgColor,
+ ...style,
+ }}
+ className={avatar({ context, notification })}
+ {...props}
>
- {initial}
- </span>
- </div>
- )
-}
+ <span
+ aria-hidden="true"
+ className={css({
+ marginTop: '-0.3rem',
+ })}
+ >
+ {initial}
+ </span>
+ </div>
+ )
+ }
+)
+
+Avatar.displayName = 'Avatar'