1.2.3 • Published 3 years ago

use-cursor v1.2.3

Weekly downloads
889
License
MIT
Repository
github
Last release
3 years ago

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;
};