-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathairline-list.jsx
More file actions
33 lines (27 loc) · 902 Bytes
/
airline-list.jsx
File metadata and controls
33 lines (27 loc) · 902 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import React from 'react'
import { Link } from "react-router-dom"
import Pagination from '../utility/pagination'
const AirlineList = ({airlines}) => {
const [airlinesShowing, setAirlinesShowing] = React.useState(airlines.slice(0, 10))
const onPageChanged = ({ currentPage, totalPages, pageLimit }) => {
const offset = (currentPage - 1) * pageLimit
const currentSlice = airlines.slice(offset, offset + pageLimit)
setAirlinesShowing(currentSlice)
}
const listItems =
airlinesShowing.map(({ name, id }) => (
<li key={`${name}-${id}`}>
<Link className='menu' to={`/airlines/${id}`}>{name}</Link>
</li>
)
)
return (
<>
<ul className={`airline-list`}>
{listItems}
</ul>
<Pagination totalRecords={airlines.length} pageLimit={10} pageSiblings={1} onPageChanged={onPageChanged} />
</>
)
}
export default AirlineList