Skip to content

Instantly share code, notes, and snippets.

View chris-cornell's full-sized avatar

Chris Cornell chris-cornell

  • New York, NY
View GitHub Profile
@chris-cornell
chris-cornell / useCycler.ts
Created January 6, 2022 21:36
some overly memoized hooks
import { useState, useMemo, useCallback } from 'react';
function getNextIndex(curr, len, shouldLoop) {
if (curr === len - 1) return shouldLoop ? 0 : curr;
return curr + 1;
}
function getPrevIndex(curr, len, shouldLoop) {
if (curr === 0) return shouldLoop ? len - 1 : 0;
return curr - 1;