Skip to content

Instantly share code, notes, and snippets.

@zerostyle
Created February 22, 2019 23:22
Show Gist options
  • Save zerostyle/75e672378ae5ef81a69874533dac9ac7 to your computer and use it in GitHub Desktop.
Save zerostyle/75e672378ae5ef81a69874533dac9ac7 to your computer and use it in GitHub Desktop.
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)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment