@gdo-bzh/use-iterator
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.5 • Public • Published

version

use-iterator

NPM JavaScript Style Guide

iterates over a collection

Install

yarn add @gdo-bzh/use-iterator react @gdo-bzh/use-range-iterator
# or
npm i @gdo-bzh/use-iterator react @gdo-bzh/use-range-iterator -S

Usage

import React from 'react'

const Example = () => {
  const { item, next, previous, hasNext, hasPrevious } = useRangeIterator({ items:[{...}, {...}] })
}

Types

export type State<T> = {
  /**
   * start value
   */
  items: T[]
  /**
   * the number of values to navigate at a time
   */
  step: number
  /**
   * true will make navigation cycling
   */
  loop: boolean
}

export type UseIterator = {
  <T>(initialState: Partial<Omit<State<T>, 'value' | 'items'>> & Pick<State<T>, 'items'>): {
    loop: State<T>['loop']
    step: State<T>['step']
    item: T
    hasNext: boolean
    /**
     * returns true if the iteration has more Element
     */
    hasPrevious: boolean
    /**
     * iterates to the next element
     */
    next: () => void
    /**
     * iterates to the previous element
     */
    previous: () => void
  }
}

License

MIT © gdo-bzh

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.0.0-rc.5
    1
    • latest

Version History

Package Sidebar

Install

npm i @gdo-bzh/use-iterator

Weekly Downloads

1

Version

1.0.0-rc.5

License

MIT

Unpacked Size

9.42 kB

Total Files

8

Last publish

Collaborators

  • gdo