Newer
Older
import { useNavigate } from 'react-router-dom';
import { UserContext } from '../Context.js';
import Article from '../components/Article.js';
import React, { useEffect, useState, useContext} from 'react';
import axios from 'axios';
axios.defaults.withCredentials = true;
<button onClick={() => {navigate('/search');}}>
{children}
</button>
);
const [articleList, setArticleList] = useState([])
let listItem = [];
listItem = articleList.map((article)=>{
return(
<Article
requestLoadArticle()
.then((response) => {
console.log(response)
setArticleList(response.data)
})
const handleSortChange = (event) => {
console.log(event.target.value)
requestSortArticle(event.target.value)
.then((response) => {
console.log(response)
setArticleList(response.data)
})
};
return(
<div className="App">
<h1>메인 페이지 입니다.</h1>
<div className="introduction">
소개 내용을 담을 공간
</div>
<div style={{display: 'flex'}}>
<Button>검색</Button>
<select id="addInputPrior" onChange={handleSortChange}>
<option value="time">최신순</option>
<option value="like">인기순</option>
</select>
</div>
async function requestLoadArticle() {
const response = await axios({
method: 'get', // 통신할 방식
});
return response;
}
async function requestSortArticle(crit) {
const response = await axios({
url: `http://localhost:8080/article/sort/${crit}`, // 통신할 웹문서
method: 'get', // 통신할 방식
});
return response;
}