use-hookit

useHookit is a collection of useful custom React Hooks designed to boost your development productivity. It helps you build faster and more efficiently by providing reusable hooks for common UI patterns and complex logic.

useHookit ๐Ÿš€

Modern React Hooks Library - Boost your development with powerful, type-safe custom hooks

A comprehensive collection of 40+ production-ready React hooks designed to accelerate your development workflow. Built with TypeScript, optimized for performance, and crafted for real-world applications.

โœจ Features

  • Zero Dependencies - Pure React hooks, no external dependencies
  • Performance Optimized - Built with React best practices and memoization
  • Type Safe - Full TypeScript support with comprehensive type definitions
  • Tree Shakeable - Import only what you need, keep your bundle size minimal
  • Interactive Docs - Live examples and documentation with Storybook

๐Ÿš€ Quick Start

npm install use-hookit
# or
pnpm add use-hookit
# or
yarn add use-hookit
import { useDebounce, useLocalStorage, useClickOutside } from 'use-hookit';

// Debounce search input
const debouncedSearch = useDebounce(searchTerm, 300);

// Persistent state (localStorage)
const [theme, setTheme, removeTheme] = useLocalStorage('theme', 'light');

// Click outside detection
const ref = useClickOutside(() => setModalOpen(false));

๐Ÿ“š Hook Categories

UI Hooks - DOM Interactions

import {
	useClickOutside,
	useEventListener,
	useIntersectionObserver,
	useLongPress,
} from 'use-hookit/ui';

Utility Hooks - Data Management

import {
	useArray,
	useObject,
	useSet,
	useMap, // Data structures
	useBoolean,
	useLoading,
	useCopyToClipboard, // State management
	useWindowSize,
	useMediaQuery,
	useNetworkStatus,
	useGeolocation, // Browser APIs
	useUrlQuery, // URL query management
} from 'use-hookit/utility';

// Boolean state
const { value, toggle, setTrue, setFalse } = useBoolean({ initialValue: false });

// Loading state
const { isLoading, startLoading, stopLoading } = useLoading();

Performance Hooks - Optimization

import { useDebounce, useThrottle } from 'use-hookit/performance';

Lifecycle Hooks - Component Lifecycle

import { useIsMounted, usePrevious } from 'use-hookit/lifecycle';

Storage Hooks - Persistence

import { useLocalStorage, useSessionStorage } from 'use-hookit/storage';

// LocalStorage (with TypeScript generic)
const [user, setUser, removeUser] = useLocalStorage<{ name: string; email: string }>('user', {
	name: '',
	email: '',
});

// SessionStorage
const [token, setToken, removeToken] = useSessionStorage('token', '');

๐ŸŽฏ Featured Hooks

Data Structure Hooks

// Array management with 20+ methods
const [array, { push, pop, filter, map, sort, reverse }] = useArray({
	initialValue: [1, 2, 3],
}); // [T[], ArrayOperations<T>]

// Object state management
const [obj, { set, has, remove, merge, pick, omit }] = useObject({
	initialValue: { name: 'John' },
}); // [T, ObjectOperations<T>]

// Set operations
const [set, { add, delete: remove, union, intersection, difference }] = useSet({
	initialValue: ['apple', 'banana'],
}); // [Set<T>, SetOperations<T>]

// Map key-value management
const [map, { set, get, has, delete: remove, filter, map: mapValues }] = useMap({
	initialValue: [['key', 'value']],
}); // [Map<K, V>, MapOperations<K, V>]

TypeScript Generic Example

// useArray<number>
const [numbers, { push }] = useArray<number>({ initialValue: [1, 2, 3] });

// useMap<string, number>
const [scoreMap, { set }] = useMap<string, number>({ initialValue: [['math', 100]] });

UI Interaction Hooks

// Click outside detection
const ref = useClickOutside(() => setOpen(false));

// Long press detection
const { handlers, isLongPressing } = useLongPress({
	onLongPress: () => console.log('Long pressed!'),
	delay: 500,
});

// Intersection observer
const { isIntersecting, ref } = useIntersectionObserver({
	threshold: 0.5,
});

Performance Hooks

// Debounce values
const debouncedSearch = useDebounce(searchTerm, 300);

// Throttle callbacks
const throttledScroll = useThrottle(handleScroll, 100);

Browser API Hooks

// Window size with breakpoints
const { width, height, isMobile, isDesktop } = useWindowSize();

// Media queries
const isDarkMode = useMediaQuery('(prefers-color-scheme: dark)');

// Network status
const { isOnline, isOffline } = useNetworkStatus();

// Geolocation
const { position, loading, error } = useGeolocation();

URL Query Management

// URL ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ ๊ด€๋ฆฌ
const { query, set, get, clear, isEmpty } = useUrlQuery({
	page: 1,
	search: '',
	category: 'all',
});

// ํŠน์ • ํŒŒ๋ผ๋ฏธํ„ฐ ์„ค์ •
set('page', 2);

// ํŒŒ๋ผ๋ฏธํ„ฐ ๊ฐ’ ๊ฐ€์ ธ์˜ค๊ธฐ
const currentPage = get('page');

// ๋ชจ๋“  ํŒŒ๋ผ๋ฏธํ„ฐ ์ œ๊ฑฐ
clear();

๐Ÿ“– Documentation

๐Ÿ”— Live Storybook Documentation & Examples

๋ชจ๋“  ํ›…์˜ ์‹ค์‹œ๊ฐ„ ์˜ˆ์ œ์™€ ์ƒ์„ธ ๋ฌธ์„œ๋ฅผ Storybook์—์„œ ํ™•์ธํ•˜์„ธ์š”.


๐Ÿ“ฆ Bundle Size

  • Core: ~2KB gzipped
  • Individual hooks: ~0.5-2KB each
  • Tree-shakeable: Only import what you use

๐Ÿ› ๏ธ Development

# Install dependencies
pnpm install

# Run tests
pnpm test

# Run Storybook locally
pnpm run storybook

# Build library
pnpm run build

๐Ÿ“‹ Requirements

  • React 18.0.0 or higher
  • TypeScript 4.5+ (recommended)

๐Ÿ“„ License

MIT ยฉ useHookit