fix(Toolbox): Stop rerendering on every action

getJwtDisabledButtons which is used as a selector will create a new array every time it is called. This will lead to unneccessary rerenders on every action where there is no difference in the result of getJwtDisabledButtons because the reference of the array will be different.
This commit is contained in:
Hristo Terezov
2024-05-22 13:36:53 -05:00
parent 46ea1f577c
commit d5dd5e4560
4 changed files with 56 additions and 11 deletions

View File

@@ -5,7 +5,7 @@ import { makeStyles } from 'tss-react/mui';
import { IReduxState } from '../../../app/types';
import { isMobileBrowser } from '../../../base/environment/utils';
import { isLocalParticipantModerator } from '../../../base/participants/functions';
import { getLocalParticipant, isLocalParticipantModerator } from '../../../base/participants/functions';
import ContextMenu from '../../../base/ui/components/web/ContextMenu';
import { isReactionsButtonEnabled, shouldDisplayReactionsButtons } from '../../../reactions/functions.web';
import {
@@ -97,7 +97,9 @@ export default function Toolbox({
const toolbarButtonsToUse = toolbarButtons || reduxToolbarButtons;
const chatOpen = useSelector((state: IReduxState) => state['features/chat'].isOpen);
const isDialogVisible = useSelector((state: IReduxState) => Boolean(state['features/base/dialog'].component));
const jwtDisabledButtons = useSelector(getJwtDisabledButtons);
const jwt = useSelector((state: IReduxState) => state['features/base/jwt'].jwt);
const localParticipant = useSelector(getLocalParticipant);
const jwtDisabledButtons = getJwtDisabledButtons(jwt, localParticipant?.features);
const reactionsButtonEnabled = useSelector(isReactionsButtonEnabled);
const _shouldDisplayReactionsButtons = useSelector(shouldDisplayReactionsButtons);
const toolbarVisible = useSelector(isToolboxVisible);