Newer
Older
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
import {useEffect, useState} from "react";
import CatHistoryLine from "./CatHistoryLine";
type CatHistoryRecord = {
event: string,
time: Date
}
function CatHistory() {
const [history, setHistory] = useState<CatHistoryRecord[]>([])
useEffect( () => {
const newRecords = [
{event: "entré", time: new Date()},
{event: "entré", time: new Date()},
{event: "sorti", time: new Date()}
];
setHistory(newRecords)
}, [])
console.log(history)
/*useEffect(() => {
fetch("https://api.example.com/items")
.then(res => res.json())
.then(
(result) => {
setIsLoaded(true);
setItems(result);
},
// Note: it's important to handle errors here
// instead of a catch() block so that we don't swallow
// exceptions from actual bugs in components.
(error) => {
setIsLoaded(true);
setError(error);
}
)
}, [])*/
return(
<div>
{history.map((chl, index) => (<CatHistoryLine key={index} lineData={chl} />))}
</div>
)
}
export default CatHistory