Skip to content

Commit

Permalink
refactor: apply suggestions about declaring state selector
Browse files Browse the repository at this point in the history
Co-authored-by: Anton Arnautov <43254280+arnautov-anton@users.noreply.github.com>
  • Loading branch information
MartinCupela and arnautov-anton authored Sep 11, 2024
1 parent 4f120a4 commit d3133b8
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/components/Dialog/hooks/useDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ export const useDialog = ({ id }: GetOrCreateDialogParams) => {
export const useDialogIsOpen = (id: string) => {
const { dialogManager } = useDialogManager();
const dialogIsOpenSelector = useCallback(
({ dialogsById }: DialogManagerState) => [!!dialogsById[id]?.isOpen],
({ dialogsById }: DialogManagerState) => [!!dialogsById[id]?.isOpen] as const,
[id],
);
return useStateStore<DialogManagerState, boolean[]>(dialogManager.state, dialogIsOpenSelector)[0];
return useStateStore(dialogManager.state, dialogIsOpenSelector)[0];
};

const openedDialogCountSelector = (nextValue: DialogManagerState) => [
Object.values(nextValue.dialogsById).reduce((count, dialog) => {
if (dialog.isOpen) return count + 1;
return count;
}, 0),
];
] as const;

export const useOpenedDialogCount = () => {
const { dialogManager } = useDialogManager();
return useStateStore<DialogManagerState, number[]>(
return useStateStore(
dialogManager.state,
openedDialogCountSelector,
)[0];
Expand Down

0 comments on commit d3133b8

Please sign in to comment.