Archived
added db event fetching
This commit is contained in:
1 parent
bcffc032d3
commit
78a2308ca6
1 file changed
+22
-5
+22
-5
@@ -1,15 +1,32 @@
|
|||||||
|
import { useState } from "react";
|
||||||
import { Stack } from "react-bootstrap";
|
import { Stack } from "react-bootstrap";
|
||||||
import styles from "./index.module.scss";
|
import styles from "./index.module.scss";
|
||||||
|
import axios from "axios";
|
||||||
|
import { BACKEND_URL } from "../../constants";
|
||||||
|
|
||||||
export const Home = () => {
|
export const Home = () => {
|
||||||
const data =[{"name":"test1"},{"name":"test2"}];
|
const [events, updateEvents] = useState([]);
|
||||||
|
|
||||||
|
axios
|
||||||
|
.get(`${BACKEND_URL}/api/getEvents`)
|
||||||
|
.then((res) => {
|
||||||
|
if (res.status !== 200) throw new Error(`Request failed with code ${res.status}: ${res.statusText}`);
|
||||||
|
updateEvents(res.data);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
console.error(`Failed to fetch events. ${e}`);
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={styles.con}>
|
<div className={styles.con}>
|
||||||
<Stack gap={1}>
|
<Stack gap={1}>
|
||||||
{data.map(function(d, idx){
|
{events.map((e, i) => {
|
||||||
return (<div key={idx} className={styles.item}>{d.name}</div>)
|
return (
|
||||||
})}
|
<div key={i} className={styles.item}>
|
||||||
|
{e.mess}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
})}
|
||||||
</Stack>
|
</Stack>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in new issue
Block a user