import React, { useState, useEffect } from 'react'; import Menu from '../Components/Menu'; import axios from 'axios'; import { Link, Redirect } from 'react-router-dom'; import { Container, Row, Col, Accordion, Button } from 'react-bootstrap'; import CARD from '../Components/Card'; function Notice() { const [notices, setNotices] = useState([]); const [user, setUser] = useState({ role: "" }) const [state, setState] = useState() useEffect(() => { acheck(); getNotice(); }, []); if (state) return ; function acheck() { axios.get(`/api/users/${localStorage.getItem('_id')}`, { headers: { authorization: localStorage.getItem('token') }, }) .then(res => { if (res.status !== 201) { alert(res.data.error); localStorage.clear(); setState(true); } if (res.data.role == "admin") { setUser(res.data) } }).catch(err => { alert(err.error) }); } function getNotice() { axios.get(`/api/notices`) .then(res => { console.log('res.data=', res.data) if (res.status !== 201) { alert(res.data.error); } setNotices(res.data); }) .catch(err => { alert(err.error) }); } return (

공지사항 {user.role === "admin" ? ( ) : null}

{notices.map((notice, index) => )}
) } export default Notice