Skip to content

Commit

Permalink
feat(lib): add new removeMany function to delete many data at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Suzan-Dev committed Sep 29, 2022
1 parent a6db6bb commit 713c3e7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ export const useComplexState = <T extends Partial<T>>(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,
Expand All @@ -77,5 +87,6 @@ export const useComplexState = <T extends Partial<T>>(initialValue: T[]) => {
update,
partialUpdate,
remove,
removeMany,
};
};

0 comments on commit 713c3e7

Please sign in to comment.