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;
function Button({ history, children }) {
const navigate = useNavigate();
return (
<button style={{ width: '40px', height: '30px' }} onClick={() => { navigate('/search'); }}>
{children}
</button>
);
listItem = articleList.map((article) => {
return (
<Article
key={article._id}
data={article}
></Article>
requestSortArticle("time")
.then((response) => {
console.log(response)
setArticleList(response.data)
const handleSortChange = (event) => {
requestSortArticle(event.target.value)
.then((response) => {
console.log(response)
setArticleList(response.data)
})
};
</div>
<div style={{ display: 'flex' }}>
<select id="addInputPrior" defaultValue={"time"} onChange={handleSortChange}>
<option value="time">최신순</option>
<option value="like">인기순</option>
</select>
</div>
{listItem}
</div>);
async function requestSortArticle(crit) {
const response = await axios({
url: `http://localhost:8080/article/?criteria=${crit}`, // 통신할 웹문서