Skip to content

Instantly share code, notes, and snippets.

View zerostyle's full-sized avatar
🌋
🌊

Joshua Stearns zerostyle

🌋
🌊
View GitHub Profile
@zerostyle
zerostyle / pagination.js
Created February 22, 2019 23:22
Pagination Previous and Next Pattern (React)
const previous = currentIndex => {
const { items, setActiveId } = this.props
const index = (currentIndex - 1 + items.length) % items.length
setActiveId(items[index].id)
}
const next = currentIndex => {
const { items, setActiveId } = this.props
const index = (currentIndex + 1) % items.length
setActiveId(items[index].id)