I have an app that fetch JSON data from a DB JSON and I want to paginate this data like for an example to show 1 image per page. How can I do it? Here is my DB JSON
db.json file:
"interiores": [
{
"images": [
"img_01", "img_02", "img_03", "img_04", "img_05"
]
}
]
I have a React component code to that fetch the JSON data by axios. It is working successfully.
React component file:
import React, { Component } from 'react'
import axios from 'axios'
const URL_INTERIORES = 'http://localhost:3001/interiores';
class Interiores extends Component {
constructor(props) {
super(props)
this.state = {
interiores: [],
}
}
componentDidMount() {
axios.get(URL_INTERIORES)
.then(res => {
this.setState({ interiores: res.data })
})
}
render() {
return (
<div>
{this.state.interiores.map(item =>
<div>
<div className="gallery images-box-1">
{
item.images
.map((img) => {
return (
<a href={`../images/${img}.jpg`}>
<img src={`../images/${img}_thumb.jpg`} alt="" />
</a>
)
})
}
</div>
</div>
)}
</div>
);
}
}
export default Interiores;
Here is the code made by SO user Piotr Berebecki can help . This code is working successfully It is a pagination of returning items from a simply array. I want to do the same thing but returning data from JSON DB shown above. How can I do? How can I solve it? Thank you.