-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgeneric-table-component.tsx
More file actions
53 lines (46 loc) · 1015 Bytes
/
generic-table-component.tsx
File metadata and controls
53 lines (46 loc) · 1015 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from "react"
import { getDeepValue } from "../utils"
type TableProps<TItem> = {
item: TItem
renderItem: (item: TItem) => React.ReactNode
}
const Table = <TItem,>({ item, renderItem }: TableProps<TItem>) => {
return null
}
const obj = {
a: {
b: "2",
c: 3,
},
d: {
e: 4,
f: "5",
},
}
const GenericTableComponent = () => {
const value = getDeepValue(obj, "a", "c")
// type data value adalah number
console.log(value)
const value2 = getDeepValue(obj, "a", "b")
// type data value2 adalah string
console.log(value2)
return (
<div>
<Table
item={{ foo: "2", bar: "3" }}
renderItem={item => {
// type data item adalah {foo: string, baar: string}
return <div />
}}
/>
<Table
item={{ a: "2", b: 3 }}
renderItem={item => {
// type data item adalah {a: string, b: number}
return <div />
}}
/>
</div>
)
}
export default GenericTableComponent