-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathApp.tsx
80 lines (67 loc) · 1.74 KB
/
App.tsx
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import React from 'react';
import FirstExample from './FirstExample';
import SecondExample from './SecondExample';
import ThirdExample from './ThirdExample';
import FourthExample from './FourthExample';
import FifthExample from './FifthExample';
import SixthExample from './SixthExample';
import SeventhExample from './SeventhExample';
import EighthExample from './EighthExample';
import NinthExample from './NinthExample';
import TenthExample from './TenthExample';
const getExample = (id: number) => {
switch (id) {
case 1:
return FirstExample;
case 2:
return SecondExample;
case 3:
return ThirdExample;
case 4:
return FourthExample;
case 5:
return FifthExample;
case 6:
return SixthExample;
case 7:
return SeventhExample;
case 8:
return EighthExample;
case 9:
return NinthExample;
case 10:
return TenthExample;
default:
return SecondExample;
}
};
const App = () => {
const urlParams = new URLSearchParams(window.location.search);
const exampleFromUrl = Number(urlParams.get('example'));
const [exampleId, setExampleId] = React.useState(1);
const Example = getExample(exampleFromUrl || exampleId);
return (
<div>
{!exampleFromUrl && (
<div>
<h2>Example {exampleId}</h2>
<p>Choose an example:</p>
{[...Array(10).keys()].map((value) => (
<button
key={value}
onClick={() => setExampleId(value + 1)}
style={{
marginRight: 8,
}}
>
{`Example ${value + 1}`}
</button>
))}
</div>
)}
<hr />
<Example />
</div>
);
};
export default App;