-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.tsx
More file actions
80 lines (72 loc) · 1.43 KB
/
example.tsx
File metadata and controls
80 lines (72 loc) · 1.43 KB
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, { useState } from 'react';
import { JsonDiffComponent } from 'json-diff-react';
const initialA = {
a: 1,
b: "test",
c: [
1,
2,
3
],
d: {
e: "test",
f: {
g: [1, "asdf"]
}
}
};
const initialB = {
a: 1,
b: "changed",
c: [
1,
3
],
d: {
e: "test",
f: {
g: [1, 2]
}
}
}
function Editor({ value, callback } : { value: string, callback: any }) {
return (
<textarea value={value} onChange={callback} cols={40} rows={40}>
</textarea>
);
}
function App() {
const [a, setA] = useState(JSON.stringify(initialA, null, 2));
const [b, setB] = useState(JSON.stringify(initialB, null, 2));
function Result(): JSX.Element {
try {
const parsedA = JSON.parse(a);
const parsedB = JSON.parse(b);
return <JsonDiffComponent jsonA={parsedA} jsonB={parsedB} />;
} catch(e: any) {
return <p>{"Error:" + e.message}</p>;
}
}
return (
<div>
<table>
<tbody>
<tr>
<td>
<Editor
value={a}
callback={(e: React.ChangeEvent<HTMLTextAreaElement>) => setA(e.target.value)} />
</td>
<td>
<Editor
value={b}
callback={(e: React.ChangeEvent<HTMLTextAreaElement>) => setB(e.target.value)} />
</td>
</tr>
</tbody>
</table>
<Result />
</div>
);
}
export default App;