-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
63 lines (50 loc) · 1.21 KB
/
App.tsx
File metadata and controls
63 lines (50 loc) · 1.21 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
import React from "./core/React";
function Hello() {
console.log("hello");
const [hello, setHello] = React.useState("hello");
function handleClick() {
setHello("hello world");
}
React.useEffect(() => {
console.log("This should be called once - Hello");
return () => {
console.log("clean up - Hello");
};
}, [hello]);
return (
<div>
{hello}
<button onClick={handleClick}>click me!</button>
</div>
);
}
function App() {
console.log("App");
const [bar, setBar] = React.useState("bar");
const [count, setCount] = React.useState(10);
function handleClickRoot() {
setCount((c) => c + 1);
setBar("bar");
}
React.useEffect(() => {
console.log("This useEffect should be called once.");
return () => {
console.log("clean up - should not be called");
};
}, []);
React.useEffect(() => {
console.log("This useEffect should be called when count changed.");
return () => {
console.log("clean up - should be called");
};
}, [count]);
return (
<div class="app">
{count}
<div>{bar}</div>
<Hello />
<button onClick={handleClickRoot}>click me app!</button>
</div>
);
}
export default App;