Skip to content

Commit f0fd00e

Browse files
committed
fix: use-set reset
1 parent f3a9dd4 commit f0fd00e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/hooks/src/useSet/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ function useSet<T = any>(
1313
): [state: Ref<Set<any>>, actions: Actions<T>];
1414

1515
function useSet<T = any>(initialValue?: T[]) {
16-
const initialSet = initialValue ? new Set(initialValue) : new Set();
17-
const state = ref(initialSet);
16+
const getInitValue = () => {
17+
return initialValue === undefined ? new Set<T>() : new Set(initialValue);
18+
};
19+
const state = ref(getInitValue());
1820

1921
const actions: Actions<T> = {
2022
add: (value: T) => {
@@ -26,7 +28,7 @@ function useSet<T = any>(initialValue?: T[]) {
2628
has: (value: T) => state.value.has(value),
2729
clear: () => state.value.clear(),
2830
reset: () => {
29-
state.value = new Set();
31+
state.value = getInitValue();
3032
},
3133
};
3234

0 commit comments

Comments
 (0)