use-cursor
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

use-cursor

semantic-release npm Build Status

What is this?

A React hook to cycle an index within some max length

Installation

yarn add use-cursor

Usage

import React from "react";
import { useCursor } from "use-cursor";

const App: React.FC = () => {
  const { index, cursor, handlePrev, handleNext } = useCursor({ max: 10 });

  return (
    <button onClick={handleNext}>Next</button>
    <button onClick={handlePrev}>Previous</button>
    <pre>
      <code>{JSON.stringify({ index, cursor })}</code>
    </pre>
  );
};

Interface

const useCursor: ({
  max,
  initialCursor
}: {
  max: number;
  initialCursor?: number | undefined;
}) => {
  handlePrev: () => void;
  handleNext: () => void;
  cursor: number;
  index: number;
};

Readme

Keywords

none

Package Sidebar

Install

npm i use-cursor

Weekly Downloads

2,055

Version

1.2.3

License

MIT

Unpacked Size

4.86 kB

Total Files

7

Last publish

Collaborators

  • dzuc