JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q12286F
  • License MIT

Package Exports

  • @gdo-bzh/use-iterator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@gdo-bzh/use-iterator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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