import React, { useState, useEffect, useRef } from 'react'; import Menu from '../Components/Menu'; import axios from 'axios'; import styled from 'styled-components'; function Notice() { const [notices, setNotices] = useState([]); useEffect(() => { getNotice(); }, []); function dateForm(day) { const post_day = new Date(day); let year = post_day.getFullYear(); let month = post_day.getMonth() + 1; let date = post_day.getDate(); month = month < 10 ? '0' + month : month; date = date < 10 ? '0' + date : date; const new_date = year + "-" + month + "-" + date; return new_date } function getNotice() { axios.get(`/notices`) .then(res => { if (res.status !== 201) { alert(res.data.error); } console.log(res.data); setNotices(res.data); }) .catch(err => { alert(err.error) }); } return (

공지사항

{notices.map((notice, index) =>
{notice.notice_title}
{notice.notice_author}
{dateForm(notice.post_date)}
{notice.notice_content}
)}
) } export default Notice