import React, {useEffect, useState} from "react"; import "./posts.scss"; import Tag from "../tag/tag"; import * as axios from "axios"; import Loading from "./loading/Loading"; import Link from "next/link"; import 'moment/locale/fr'; import Moment, { now } from 'react-moment'; const Posts = () => { const [isLoading, setLoading] = useState(true); const [getPosts, setPosts] = useState([]); useEffect(() => { loadPosts() .then(() => { setLoading(false); }) .catch(error => console.log(error)); }, []); const loadPosts = async () => { await axios.get("https://localhost:8080/api/posts") .then(response => { setPosts(response); }) .catch(error => console.log(error)); } const renderPosts = () => { if (getPosts.length) { return (
{getPosts.map(post => { return (

{post.title}

{now}
) })}
) } else { return (

Il n'y a malheureusement aucun article de posté pour le moment. 😕

) } }; return (
Mon blog {isLoading ? : renderPosts()}
) }; export default Posts;