File tree Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Expand file tree Collapse file tree 1 file changed +7
-5
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import {useState} from 'react';
2
2
3
3
export interface Actions < T > {
4
4
set : ( list : T [ ] ) => void ;
5
+ clear : ( ) => void ;
5
6
updateAt : ( index : number , item : T ) => void ;
6
7
remove : ( index : number ) => void ;
7
8
push : ( item : T ) => void ;
@@ -14,18 +15,19 @@ const useList = <T>(initialList: T[] = []): [T[], Actions<T>] => {
14
15
15
16
return [ list , {
16
17
set,
17
- updateAt : ( index , entry ) => set ( [
18
+ clear : ( ) => set ( [ ] ) ,
19
+ updateAt : ( index , entry ) => set ( list => [
18
20
...list . slice ( 0 , index ) ,
19
21
entry ,
20
22
...list . slice ( index + 1 )
21
23
] ) ,
22
- remove : ( index ) => set ( [
24
+ remove : ( index ) => set ( list => [
23
25
...list . slice ( 0 , index ) ,
24
26
...list . slice ( index + 1 )
25
27
] ) ,
26
- push : ( entry ) => set ( [ ...list , entry ] ) ,
27
- filter : ( fn ) => set ( list . filter ( fn ) ) ,
28
- sort : ( fn ?) => set ( [ ...list ] . sort ( fn ) ) ,
28
+ push : ( entry ) => set ( list => [ ...list , entry ] ) ,
29
+ filter : ( fn ) => set ( list => list . filter ( fn ) ) ,
30
+ sort : ( fn ?) => set ( list => [ ...list ] . sort ( fn ) ) ,
29
31
} ] ;
30
32
} ;
31
33
You can’t perform that action at this time.
0 commit comments