This repository has been archived on 2026-09-07. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
eco-hack/src/pages/Home/index.js
T
2021-10-02 21:47:55 +02:00

39 lines
1.2 KiB
JavaScript

import { useState, useEffect } from "react";
import { Stack } from "react-bootstrap";
import styles from "./index.module.scss";
import axios from "axios";
import { BACKEND_URL } from "../../constants";
export const Home = () => {
const [events, updateEvents] = useState([]);
useEffect(() => {
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 (
<div className={styles.con}>
<Stack gap={1}>
{events.map((e, i) => {
return (
<div key={i} className={styles.item}>
<span className={styles.location}>{e.name}</span> <br></br>
<span>{e.date}</span>
</div>
);
})}
<p className={styles.more}>więcej</p>
</Stack>
</div>
);
};