Use memoized callbacks when passing to components

This commit is contained in:
Daniel Abramov 2023-07-03 18:28:43 +01:00
parent caa3a7e8d0
commit 2293cbf1f0
2 changed files with 19 additions and 7 deletions

View File

@ -42,6 +42,12 @@ interface Props {
export const CallTypeDropdown: FC<Props> = ({ callType, setCallType }) => {
const { t } = useTranslation();
const onAction = (key: React.Key) => {
setCallType(key.toString() as CallType);
};
const onClose = () => {};
return (
<PopoverMenuTrigger placement="bottom">
<Button variant="dropdown" className={commonStyles.headline}>
@ -55,11 +61,8 @@ export const CallTypeDropdown: FC<Props> = ({ callType, setCallType }) => {
<Menu
{...props}
label={t("Call type menu")}
onAction={(key) => {
const callType = key.toString();
setCallType(callType as CallType);
}}
onClose={() => {}}
onAction={onAction}
onClose={onClose}
>
<Item key={CallType.Video} textValue={t("Video call")}>
<VideoIcon />

View File

@ -38,6 +38,15 @@ export function GridLayoutMenu({ layout, setLayout }: Props) {
const { t } = useTranslation();
const tooltip = useCallback(() => t("Change layout"), [t]);
const onAction = useCallback(
(key: React.Key) => {
setLayout(key.toString() as Layout);
},
[setLayout]
);
const onClose = useCallback(() => {}, []);
return (
<PopoverMenuTrigger placement="bottom right">
<TooltipTrigger tooltip={tooltip}>
@ -49,8 +58,8 @@ export function GridLayoutMenu({ layout, setLayout }: Props) {
<Menu
{...props}
label={t("Grid layout menu")}
onAction={(key) => setLayout(key.toString() as Layout)}
onClose={() => {}}
onAction={onAction}
onClose={onClose}
>
<Item key="freedom" textValue={t("Freedom")}>
<FreedomIcon />