File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
react-typescript-demo/src Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import { DomRef } from './components/refs/DomRef'
15
15
import { MutableRef } from './components/refs/MutableRef'
16
16
import './App.css'
17
17
import { Counter } from './components/class/Counter'
18
+ import { List } from './components/generics/List'
18
19
19
20
function App ( ) {
20
21
const personName = {
@@ -63,6 +64,28 @@ function App() {
63
64
< DomRef />
64
65
< MutableRef />
65
66
< Counter message = 'The count value is ' />
67
+ < List
68
+ items = { [ 'Batman' , 'Superman' , 'Wonder Woman' ] }
69
+ onClick = { item => console . log ( item ) }
70
+ />
71
+ < List items = { [ 1 , 2 , 3 ] } onClick = { item => console . log ( item ) } />
72
+ < List
73
+ items = { [
74
+ {
75
+ first : 'Bruce' ,
76
+ last : 'Wayne'
77
+ } ,
78
+ {
79
+ first : 'Clark' ,
80
+ last : 'Kent'
81
+ } ,
82
+ {
83
+ first : 'Princess' ,
84
+ last : 'Diana'
85
+ }
86
+ ] }
87
+ onClick = { item => console . log ( item ) }
88
+ />
66
89
</ div >
67
90
)
68
91
}
Original file line number Diff line number Diff line change
1
+ type ListProps < T > = {
2
+ items : T [ ]
3
+ onClick : ( value : T ) => void
4
+ }
5
+
6
+ export const List = < T extends { id : number } > ( {
7
+ items,
8
+ onClick
9
+ } : ListProps < T > ) => {
10
+ return (
11
+ < div >
12
+ < h2 > List of items</ h2 >
13
+ { items . map ( ( item , index ) => {
14
+ return (
15
+ < div key = { item . id } onClick = { ( ) => onClick ( item ) } >
16
+ { item }
17
+ </ div >
18
+ )
19
+ } ) }
20
+ </ div >
21
+ )
22
+ }
You can’t perform that action at this time.
0 commit comments