@@ -43,35 +43,30 @@ export const Demo = ShowDemo({
43
43
}
44
44
} ) ;
45
45
46
- interface UpsertDemoType {
47
- id : string ;
48
- text : string ;
49
- }
50
-
51
46
export const UpsertDemo = ShowDemo ( {
52
47
setup ( ) {
53
48
54
- const upsertPredicate = ( a : UpsertDemoType , b : UpsertDemoType ) => a . id === b . id ;
55
- const upsertInitialItems : UpsertDemoType [ ] = [
56
- { id : '1' , text : 'Sample' } ,
57
- { id : '2' , text : 'Example' } ,
49
+ const upsertPredicate = ( a , b ) => a . id === b . id ;
50
+ const upsertInitialItems = [
51
+ { id : '1' , text : 'Sample' } ,
52
+ { id : '2' , text : 'Example' } ,
58
53
] ;
59
54
60
- const [ list , { upsert, reset, removeAt } ] = useList ( upsertInitialItems ) ;
55
+ const [ list , { upsert, reset, removeAt} ] = useList ( upsertInitialItems ) ;
61
56
62
57
return ( ) => (
63
- < div style = { { display : 'inline-flex' , flexDirection : 'column' } } >
58
+ < div style = { { display : 'inline-flex' , flexDirection : 'column' } } >
64
59
{ list . value . map ( ( item , index ) => (
65
60
< div key = { item . id } >
66
61
< input
67
62
value = { item . text }
68
- onChange = { ( e : Event ) => upsert ( upsertPredicate , { ...item , text : e . target ?. value } ) }
63
+ onChange = { ( e ) => upsert ( upsertPredicate , { ...item , text : e . target ?. value } ) }
69
64
/>
70
65
< button onClick = { ( ) => removeAt ( index ) } > Remove</ button >
71
66
</ div >
72
67
) ) }
73
68
< button
74
- onClick = { ( ) => upsert ( upsertPredicate , { id : ( list . value . length + 1 ) . toString ( ) , text : '' } ) } >
69
+ onClick = { ( ) => upsert ( upsertPredicate , { id : ( list . value . length + 1 ) . toString ( ) , text : '' } ) } >
75
70
Add item
76
71
</ button >
77
72
< button onClick = { ( ) => reset ( ) } > Reset</ button >
0 commit comments