File tree Expand file tree Collapse file tree 1 file changed +5
-3
lines changed
packages/hooks/src/useSet Expand file tree Collapse file tree 1 file changed +5
-3
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,10 @@ function useSet<T = any>(
13
13
) : [ state : Ref < Set < any > > , actions : Actions < T > ] ;
14
14
15
15
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 ( ) ) ;
18
20
19
21
const actions : Actions < T > = {
20
22
add : ( value : T ) => {
@@ -26,7 +28,7 @@ function useSet<T = any>(initialValue?: T[]) {
26
28
has : ( value : T ) => state . value . has ( value ) ,
27
29
clear : ( ) => state . value . clear ( ) ,
28
30
reset : ( ) => {
29
- state . value = new Set ( ) ;
31
+ state . value = getInitValue ( ) ;
30
32
} ,
31
33
} ;
32
34
You can’t perform that action at this time.
0 commit comments