Useful for managing a wrapping index for an array of items.

Overview

use-wrapping-index

Useful for managing a wrapping index for an array of items.

Usage

import useWrappingIndex from "@alexcarpenter/use-wrapping-index";

const sampleData = [{ name: "Alex" }, { name: "Stacey" }, { name: "Frankie" }];

function App() {
  const {
    activeIndex,
    previousIndex,
    nextIndex,
    moveToPreviousIndex,
    moveToNextIndex,
  } = useWrappingIndex({
    maxIndex: sampleData.length,
  });

  return (
    <>
      <p>Active index: {activeIndex}</p>
      <p>Previous index: {previousIndex}</p>
      <p>Next index: {nextIndex}</p>
      <hr />
      <p>Active user: {sampleData[activeIndex].name}</p>
      <p>Previous user: {sampleData[previousIndex].name}</p>
      <p>Next user: {sampleData[nextIndex].name}</p>
      <hr />
      <button onClick={moveToPreviousIndex}>Previous</button>
      <button onClick={moveToNextIndex}>Next</button>
    </>
  );
}

This package was based off of the use-roving-index hook by souporserious.

You might also like...

Experimental URL-CID index using b trees (chunky-trees from @mikeal)

ipfs-url-index Experimental IPFS index for URL-CID, implemented using chunky-trees B-Tree implementation. API Server Run node main.js to start the ap

Mar 14, 2022

Вlockchain feed index Google Colab

blockchain-feed-index Run Google Colab https://colab.research.google.com/drive/1OShIMVcFZ_khsUIBOIV1lzrqAGo1gfm_?usp=sharing Installation Install node

Jun 25, 2022

In this project, I built a simple HTML list of To-Do tasks. This simple web page was built using Webpack, creating everything from a JavaScript index file that imported all the modules and assets

In this project, I built a simple HTML list of To-Do tasks. This simple web page was built using Webpack, creating everything from a JavaScript index file that imported all the modules and assets

To Do List In this project, I built a simple HTML list of To-Do tasks. This simple web page was built using Webpack, creating everything from a JavaSc

Mar 31, 2022

Create a self-maintaining index via proxy

proxy-indexer Proxy-indexer allows you to easily index collections of mutable objects based on their own mutable properties. While this is relatively

Nov 18, 2022

Obsidian plugin that allows user to create a glossary of files, an index of files or both.

Obsidian Auto Glossary Auto Glossary is an Obsidian plugin to create a glossary, an index or a glossary with an index from the files you want. Feature

Dec 30, 2022

Fundamentos, estruturas, função, objeto, array e etc...

JavaScript Fundamentos, estruturas, função, array e etc... Atividades praticas detalhadas e comentadas para todo mundo entender cada tag, bons estudos

Feb 27, 2022

Complete JavaScipt Array methods Cheatsheet 🚀

Complete JavaScipt Array methods Cheatsheet 🚀

Javascript Array Cheatsheet 👾 Click to download ☝ Important 🚨 There is no way this is perfect or include all the methods. I'll try to fix/add more m

Dec 7, 2022

Draft specification for a proposed Array.fromAsync method in JavaScript.

Array.fromAsync for JavaScript ECMAScript Stage-1 Proposal. J. S. Choi, 2021. Specification available Polyfill available Why an Array.fromAsync method

Dec 14, 2022

Analisador de números utilizando Array JavaScript com Html 5 e CSS 3

Olá pessal, tudo bem? :D Esse site foi desenvolvido para analisar números armazenados em um array chamado "dados[]". Temos dois botões um input e uma

Jan 6, 2022
Releases(0.1.2)
Owner
Alex Carpenter
Web Engineer • Currently interested in CSS architecture, React, TypeScript, design systems, and state machines • He/him
Alex Carpenter
A Zotero add-on that scans your Markdown reading notes, tags the associated Zotero items, and lets you open notes for the Zotero items in Obsidian.

Zotero Obsidian Citations Adds colored tags to Zotero items that have associated Markdown notes stored in an external folder. Open an associated Markd

Dae 210 Jan 4, 2023
The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day today activies. Check out the live demo.

Todo List App The app helps you to add todo items to your list, mark completed ones and also delete finished items. Its a handy tool for your day toda

Atugonza ( Billions ) Joel 14 Apr 22, 2022
A secondhand marketplace where you can post items for sale, interact with sellers, save items you are interested in.

Curbside - the secondhand market place that's actually pleasant to use Post items for sale, interact with sellers, save items you are interested in. A

Curbside 14 Sep 9, 2022
A single-page application that allow users to add their To Do items. The items could be checked as completed and the completed task can be removed. Built with JavaScript, HTML and CSS

To Do list Application This is a single page application that allows users to keep track of their tasks. Users can add the task and also check the che

Micheal Oguntayo 4 Oct 14, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Simple webpack plugin that generates VERSION and commitInfo insert index.html during build

Html commit version plugin Simple webpack plugin that generates CommitInfo and VERSION insert index.html during build. English | 简体中文 Usage Given a we

null 13 Mar 8, 2022
Index your Google Drive Easily and Free.

Google Personal/Shared Drive Index Full White label and Customizable Index | One of a kind Supports Both My and Team/Shared Drives with Dark Mode. Cli

Moto One Fusion + 26 Sep 22, 2021
A personal semantic search engine capable of surfacing relevant bookmarks, journal entries, notes, blogs, contacts, and more, built on an efficient document embedding algorithm and Monocle's personal search index.

Revery ?? Revery is a semantic search engine that operates on my Monocle search index. While Revery lets me search through the same database of tens o

Linus Lee 215 Dec 30, 2022