import React, {useEffect, useState} from "react" import PageLayout from "../../components/PageLayout" import useAxiosTools from "../../hooks/AxiosTools" import {rainfall} from "../../types" const RainfallIndex = () => { const [page, setPage] = useState(1) const [lastPage, setLastPage] = useState(1) const [rainfalls, setRainfalls] = useState([]) const {errorCatch, errorLabel, axiosGet, axiosDelete} = useAxiosTools() useEffect(() => { fetchMesures() }, [page]) const fetchMesures = async () => { try { const res = await axiosGet(`/api/rainfalls?page=${page}`) setLastPage(res.data.meta.last_page) setRainfalls([...rainfalls, ...res.data.data]) } catch (error) { errorCatch(error) } } const handleDelete = async (rainfall: rainfall) => { try { await axiosDelete(`/api/rainfalls/${rainfall.id}`) setRainfalls(rainfalls.filter(r => r.id !== rainfall.id)) } catch (error) { errorCatch(error) } } return {errorLabel()} {rainfalls.map(rainfall => )}
Date Mesure Actions
{(new Date(rainfall.date)).toLocaleDateString()} {rainfall.value} {/**/}
{page < lastPage && }
} export default RainfallIndex