diff --git a/src/base/Base.constants.ts b/src/base/Base.constants.ts new file mode 100644 index 00000000..68e2d985 --- /dev/null +++ b/src/base/Base.constants.ts @@ -0,0 +1,11 @@ +/* + * Copyright (C) Contributors to the Suwayomi project + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + */ + +export const STABLE_EMPTY_OBJECT = Object.freeze({}) as never; + +export const STABLE_EMPTY_ARRAY = Object.freeze([]) as never[]; diff --git a/src/base/collection/hooks/useSelectableCollection.ts b/src/base/collection/hooks/useSelectableCollection.ts index e9d9eab6..05badab9 100644 --- a/src/base/collection/hooks/useSelectableCollection.ts +++ b/src/base/collection/hooks/useSelectableCollection.ts @@ -7,6 +7,7 @@ */ import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; +import { STABLE_EMPTY_ARRAY, STABLE_EMPTY_OBJECT } from '@/base/Base.constants.ts'; export type SelectableCollectionReturnType = { selectedItemIds: Id[]; @@ -26,10 +27,10 @@ export type SelectableCollectionReturnType( totalCount: number, { - itemIds = [], + itemIds = STABLE_EMPTY_ARRAY, keyCount = totalCount, currentKey, - initialState = {} as Record, + initialState = STABLE_EMPTY_OBJECT, }: { itemIds?: Id[]; keyCount?: number;