Skip to content

Commit

Permalink
Add clear() to useSet
Browse files Browse the repository at this point in the history
  • Loading branch information
suisous committed Jan 5, 2024
1 parent 325f5bd commit 5aa8436
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/useSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface StableActions<K> {
remove: (key: K) => void;
toggle: (key: K) => void;
reset: () => void;
clear: () => void;
}

export interface Actions<K> extends StableActions<K> {
Expand All @@ -25,7 +26,7 @@ const useSet = <K>(initialSet = new Set<K>()): [Set<K>, Actions<K>] => {
: new Set([...Array.from(prevSet), item])
);

return { add, remove, toggle, reset: () => setSet(initialSet) };
return { add, remove, toggle, reset: () => setSet(initialSet), clear: () => setSet(new Set()) };
}, [setSet]);

const utils = {
Expand Down

0 comments on commit 5aa8436

Please sign in to comment.