I need to create pagination in my site. I'm getting data like this from REST API:
{
"count": 4,
"next": "http://127.0.0.1:8000/api/software/?p=2",
"previous": null,
"results": [
{
"id": 4,
"category": {
"id": 10,
"parent": {
"id": 2,
"name": "Name",
"slug": "Slug",
"img": "Image"
},
"name": "Name",
"slug": null,
"img": ""
},
"title": "Title",
"content": "Content",
"image": "Image",
"pub_date": "2022-02-02",
"counter": 0,
"file": "File",
"in_archive": false
},
{
"id": 3,
"category": {
"id": 11,
"parent": {
"id": 2,
"name": "Name",
"slug": "Slug",
"img": "Image"
},
"name": "Name",
"slug": null,
"img": ""
},
"title": "Title",
"content": "Content",
"image": "Image",
"pub_date": "2022-02-02",
"counter": 0,
"file": "File",
"in_archive": false
}
]
}
In React I'm trying to get the data like this:
const [currentPage, setCurrentPage] = useState(1);
const [count, setCount] = useState(null);
const [nextPage, setNextPage] = useState(null);
const [previousPage, setPreviousPage] = useState(null);
const [valid, setValid] = useState(false);
useEffect(() => {
fetch(`http://127.0.0.1:8000/api/software/?p=${currentPage}`)
.then(response => response.json())
.then(data => {
setCount(data.count);
setNextPage(data.next);
setPreviousPage(data.previous);
setValid(true);
})
}, []);
But I have no idea how it must be and how to use it in React Component, I've not done that before.
How it has to be in React?