Fix "Maximum update depth exceeded"

Regression b63c8a548e
This commit is contained in:
schroda
2026-03-20 03:01:32 +01:00
parent b63c8a548e
commit fcf1c7fa3f
2 changed files with 14 additions and 2 deletions

View 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[];

View File

@@ -7,6 +7,7 @@
*/ */
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'; 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> = { export type SelectableCollectionReturnType<Id extends number | string, Key extends string = string> = {
selectedItemIds: Id[]; 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'>( export const useSelectableCollection = <Id extends number | string, Key extends string = 'default'>(
totalCount: number, totalCount: number,
{ {
itemIds = [], itemIds = STABLE_EMPTY_ARRAY,
keyCount = totalCount, keyCount = totalCount,
currentKey, currentKey,
initialState = {} as Record<Key, Id[]>, initialState = STABLE_EMPTY_OBJECT,
}: { }: {
itemIds?: Id[]; itemIds?: Id[];
keyCount?: number; keyCount?: number;