-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathApp.js
41 lines (33 loc) · 977 Bytes
/
App.js
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
import { useState, useEffect } from "react";
import "./App.css";
import { useFetch } from "./useFetch";
const useStopwatch = () => {
const [count, setCount] = useState(0);
useEffect(() => {
console.log("useStopwatch useEffect");
const interval = setInterval(() => {
console.log(`Count = ${count}`);
setCount((prev) => prev + 1);
}, 1000);
return () => clearInterval(interval);
}, []);
return count;
};
function App() {
const [url, setUrl] = useState(null);
const count = useStopwatch();
const { data } = useFetch({ url, onSuccess: () => console.log("success") });
console.log("App rendering");
return (
<div className="App">
<div>Hello</div>
<div>Count: {count}</div>
<div>{JSON.stringify(data)}</div>
<div>
<button onClick={() => setUrl("/jack.json")}>Jack</button>
<button onClick={() => setUrl("/sally.json")}>Sally</button>
</div>
</div>
);
}
export default App;