import React, {FC, useState, useEffect} from "react" import Card from "../Card" import useAxiosTools from "../../hooks/AxiosTools" import {AxiosError} from "axios" import {monthlyRainfall} from "../../types" const YearRainfall: FC = ({loadedAt}) => { const {errorCatch, errorLabel, setError, axiosGet} = useAxiosTools() const [data, setData] = useState([]) useEffect(() => { fetchData() }, [loadedAt]) const fetchData = async () => { try { const res = await axiosGet('/api/rainfalls/last-months') setData(res.data) } catch (e) { if (e instanceof AxiosError) { setError(e.message) } else { errorCatch(e) } } } return

Précipitations des derniers mois

{errorLabel()} {Object.entries(data) .map(([month, months]) => { return })}
Mois {(new Date).getFullYear()} {(new Date).getFullYear() - 1}
{months[0].label} {months.find(m => m.year === (new Date).getFullYear() && m.month === Number(month))?.values} {months.find(m => m.year === ((new Date).getFullYear() - 1) && m.month === Number(month))?.values}
} export default YearRainfall interface YearRainfallProps { loadedAt: Date, }