🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

@alexcarpenter/use-wrapping-index

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@alexcarpenter/use-wrapping-index

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

0.1.2
latest
Source
npm
Version published
Maintainers
1
Created
Source

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.

FAQs

Package last updated on 12 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts