Created
May 31, 2018 17:25
-
-
Save maplethorpej/c4ff3d7dc07b03ee7b061ebff0e9d36e to your computer and use it in GitHub Desktop.
Basic React pagination component.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
class Pagination extends Component { | |
render () { | |
const {totalPages, currentPage, selectFn} = this.props | |
if (totalPages <= 1) {return null} | |
const pages = Array.from({length: totalPages}, (v, k) => k + 1) | |
const PageList = pages.map((page) => { | |
const selected = currentPage === page | |
const extraClass = selected ? 'selected' : '' | |
return ( | |
<li key={page} value={page} className={extraClass} | |
onClick={(e) => {!selected && selectFn(page, e)}}> | |
{page} | |
</li> | |
) | |
}) | |
return ( | |
<ul className="pagination"> | |
{PageList} | |
</ul> | |
) | |
} | |
} | |
export default Pagination |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment