fetch
const fetchComments = async (currentPage) => {
const res = await fetch(
`https://jsonplaceholder.typicode.com/comments?_page=${currentPage}&_limit=5`
);
const data = await res.json();
return data;
};
const handlePageClick = async (data) => {
console.log(data.selected);
let currentPage = data.selected + 1;
const commentsFormServer = await fetchComments(currentPage);
setItems(commentsFormServer);
};
axios
const axiosPosts = async (currentPage) => {
const res = await axios.get(
`https://jsonplaceholder.typicode.com/comments?_page=${currentPage}&_limit=5`
);
const data = await res.data;
return data;
};
const handlePageClick = async (data) => {
console.log(data.selected);
let currentPage = data.selected + 1;
const commentsFormServer = await axiosPosts(currentPage);
setItems(commentsFormServer);
};