From 713c3e7096aba342c1cca3007c9937815db829b4 Mon Sep 17 00:00:00 2001 From: Sujan Tamang Date: Thu, 29 Sep 2022 10:39:20 +0545 Subject: [PATCH] feat(lib): add new removeMany function to delete many data at once --- src/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.tsx b/src/index.tsx index bcd23e6..76d304d 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -69,6 +69,16 @@ export const useComplexState = >(initialValue: T[]) => { }); }; + const removeMany = (indexes: number[]) => { + const filteredValidIndexes = indexes.filter( + (index) => !isInvalidOrNegativeIndex(index, complexState) + ); + + setComplexState((prevState) => { + return prevState.filter((_, idx) => !filteredValidIndexes.includes(idx)); + }); + }; + return { value: complexState, setValue: setComplexState, @@ -77,5 +87,6 @@ export const useComplexState = >(initialValue: T[]) => { update, partialUpdate, remove, + removeMany, }; };