11
src/base/Base.constants.ts
Normal file
11
src/base/Base.constants.ts
Normal file
@@ -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[];
|
||||
@@ -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<Id extends number | string, Key extends string = string> = {
|
||||
selectedItemIds: Id[];
|
||||
@@ -26,10 +27,10 @@ export type SelectableCollectionReturnType<Id extends number | string, Key exten
|
||||
export const useSelectableCollection = <Id extends number | string, Key extends string = 'default'>(
|
||||
totalCount: number,
|
||||
{
|
||||
itemIds = [],
|
||||
itemIds = STABLE_EMPTY_ARRAY,
|
||||
keyCount = totalCount,
|
||||
currentKey,
|
||||
initialState = {} as Record<Key, Id[]>,
|
||||
initialState = STABLE_EMPTY_OBJECT,
|
||||
}: {
|
||||
itemIds?: Id[];
|
||||
keyCount?: number;
|
||||
|
||||
Reference in New Issue
Block a user