beautiful-react-hooks, react-async-hook, react-query, react-use, and usehooks-ts are all npm packages that provide reusable React hooks to simplify common frontend tasks. These libraries aim to reduce boilerplate and improve code quality by encapsulating logic for state management, side effects, browser APIs, and asynchronous operations. While they share overlapping goals, they differ significantly in scope, architecture, and intended use cases — from general-purpose utility hooks (react-use, usehooks-ts) to specialized async and data-fetching solutions (react-async-hook, react-query). beautiful-react-hooks focuses on declarative event handling and lifecycle abstractions.
Managing state, side effects, and async logic in React apps often leads to repetitive useEffect and useState patterns. The libraries beautiful-react-hooks, react-async-hook, react-query, react-use, and usehooks-ts each offer prebuilt hooks to reduce this boilerplate — but they solve different problems. Let’s compare them through real-world scenarios.
beautiful-react-hooks provides hooks like useEvent, useWindowResize, and useGeolocation that automatically manage event listener setup/teardown.
// beautiful-react-hooks: auto-cleanup event listener
import { useEvent } from 'beautiful-react-hooks';
function ClickTracker() {
const onClick = useEvent('click', (event) => {
console.log('Clicked at', event.clientX, event.clientY);
});
// No manual useEffect or removeEventListener needed
return <div onClick={onClick}>Track clicks</div>;
}
react-use and usehooks-ts also offer similar hooks, but require more explicit control:
// react-use: useClick
import { useClick } from 'react-use';
function ClickTracker() {
const ref = useRef(null);
useClick(ref, () => console.log('Clicked'));
return <div ref={ref}>Track clicks</div>;
}
// usehooks-ts: useEventListener
import { useEventListener } from 'usehooks-ts';
function ClickTracker() {
const handleClick = () => console.log('Clicked');
useEventListener('click', handleClick);
return <div>Track clicks</div>;
}
react-async-hook and react-query don’t focus on DOM events — they’re purely for async and data logic.
For basic async calls (e.g., form submission), react-async-hook wraps functions and exposes loading, error, and result:
// react-async-hook
import { useAsyncCallback } from 'react-async-hook';
function LoginForm() {
const login = useAsyncCallback(async (credentials) => {
return await api.login(credentials);
});
if (login.loading) return <Spinner />;
if (login.error) return <Error msg={login.error.message} />;
return <form onSubmit={() => login.execute({ user, pass })} />;
}
react-query goes further — it treats async results as server state with caching, deduplication, and background refetching:
// react-query
import { useQuery, useMutation } from '@tanstack/react-query';
function UserProfile({ userId }) {
const { data, isLoading } = useQuery({
queryKey: ['user', userId],
queryFn: () => fetchUser(userId)
});
const mutation = useMutation({
mutationFn: updateUser,
onSuccess: () => {
// Invalidate and refetch user data
queryClient.invalidateQueries(['user', userId]);
}
});
return <div>{isLoading ? '...' : data.name}</div>;
}
react-use and usehooks-ts don’t provide dedicated async state hooks. You’d typically combine useState/useEffect manually or use useAsync from react-use (which is basic):
// react-use: simple async
import { useAsync } from 'react-use';
const { value, loading, error } = useAsync(() => fetchUser(id), [id]);
beautiful-react-hooks has no async utilities.
react-use and usehooks-ts shine here with dozens of hooks for browser features:
// react-use
import { useLocalStorage, useNetwork, useMedia } from 'react-use';
const [darkMode, setDarkMode] = useLocalStorage('theme', 'light');
const isOnline = useNetwork().online;
const isMobile = useMedia('(max-width: 768px)');
// usehooks-ts
import { useLocalStorage, useNetwork, useMediaQuery } from 'usehooks-ts';
const [darkMode, setDarkMode] = useLocalStorage('theme', 'light');
const isOnline = useNetwork().online;
const isMobile = useMediaQuery('(max-width: 768px)');
react-query and react-async-hook don’t cover these. beautiful-react-hooks includes some (e.g., useGeolocation), but far fewer than the utility-focused libraries.
Only react-query provides automatic caching, stale-while-revalidate, pagination, and mutation rollback:
// react-query handles cache keys, deduplication, background updates
const { data } = useQuery({
queryKey: ['posts'],
queryFn: fetchPosts,
staleTime: 1000 * 60 // 1 min
});
All other libraries treat async results as local component state. If two components fetch the same data, they’ll make two network requests unless you build your own cache.
usehooks-ts is built from the ground up in TypeScript with strict types:
// usehooks-ts: fully typed
const [value, setValue] = useLocalStorage<string>('key', 'default');
react-use also offers strong TypeScript support, though some hooks have looser inference.
react-query has excellent TypeScript integration, especially around query keys and mutation variables.
react-async-hook and beautiful-react-hooks support TypeScript but with less comprehensive typing in edge cases.
As of 2024, all five packages are actively maintained with recent releases. None are deprecated.
| Feature / Package | beautiful-react-hooks | react-async-hook | react-query | react-use | usehooks-ts |
|---|---|---|---|---|---|
| DOM Event Helpers | ✅ Rich | ❌ | ❌ | ✅ Good | ✅ Good |
| Async State Management | ❌ | ✅ Basic | ✅ Advanced (caching, mutations) | ✅ Basic (useAsync) | ❌ |
| Browser API Hooks | ⚠️ Limited | ❌ | ❌ | ✅ Extensive | ✅ Extensive |
| Server-State Focus | ❌ | ❌ | ✅ Yes | ❌ | ❌ |
| TypeScript-First | ⚠️ Partial | ⚠️ Partial | ✅ Excellent | ✅ Strong | ✅ Strict |
react-query is the industry standard.beautiful-react-hooks reduces boilerplate.react-async-hook is lightweight and sufficient.react-use (larger ecosystem) or usehooks-ts (cleaner TS, smaller API).Don’t mix react-query with the others for data fetching — it solves that problem completely. But combining react-query with usehooks-ts (for useDebounce, useLocalStorage, etc.) is a common and effective pattern in production apps.
Choose react-use if you need a broad collection of high-quality, battle-tested hooks covering browser APIs (e.g., localStorage, media queries), sensors (e.g., mouse, network status), and utilities (e.g., previous value, timeout). It’s excellent as a general-purpose hook toolkit but doesn’t specialize in async or server-state management.
Choose usehooks-ts when you prefer TypeScript-first, minimal, and well-documented implementations of common custom hooks (like useLocalStorage, useDebounce, or useWindowSize). It’s a solid alternative to react-use with stricter type safety and simpler internals, but similarly avoids complex async orchestration.
Choose react-query for robust server-state management — especially when your app relies heavily on data fetching from APIs. It provides automatic caching, background updates, pagination, mutations, and devtools out of the box. Use it when you need to minimize network requests and keep UI data synchronized with backend sources.
Choose react-async-hook when you want a lightweight, focused solution for managing async function states (loading, error, result) without external dependencies. It’s ideal for wrapping simple API calls or async computations in components, but lacks advanced features like caching, retries, or background refetching.
Choose beautiful-react-hooks if you need clean, declarative hooks for DOM events (like clicks, scrolls, or window resizing) with built-in cleanup and dependency management. It’s well-suited for interactive UIs where you want to avoid manual useEffect boilerplate for event listeners, but it doesn’t handle data fetching or caching.
libreact.
npm i react-use
useBattery — tracks device battery state. useGeolocation — tracks geo location state of user's device. useHover and useHoverDirty — tracks mouse hover state of some element. useHash — tracks location hash value. useIdle — tracks whether user is being inactive.useIntersection — tracks an HTML element's intersection. useKey, useKeyPress, useKeyboardJs, and useKeyPressEvent — track keys. useLocation and useSearchParam — tracks page navigation bar location state.useLongPress — tracks long press gesture of some element.useMedia — tracks state of a CSS media query. useMediaDevices — tracks state of connected hardware devices.useMotion — tracks state of device's motion sensor.useMouse and useMouseHovered — tracks state of mouse position. useMouseWheel — tracks deltaY of scrolled mouse wheel. useNetworkState — tracks the state of browser's network connection. useOrientation — tracks state of device's screen orientation.usePageLeave — triggers when mouse leaves page boundaries.useScratch — tracks mouse click-and-scrub state.useScroll — tracks an HTML element's scroll position. useScrolling — tracks whether HTML element is scrolling.useStartTyping — detects when user starts typing.useWindowScroll — tracks Window scroll position. useWindowSize — tracks Window dimensions. useMeasure and useSize — tracks an HTML element's dimensions. createBreakpoint — tracks innerWidthuseScrollbarWidth — detects browser's native scrollbars width. usePinchZoom — tracks pointer events to detect pinch zoom in and out status. useAudio — plays audio and exposes its controls. useClickAway — triggers callback when user clicks outside target area.useCss — dynamically adjusts CSS.useDrop and useDropArea — tracks file, link and copy-paste drops.useFullscreen — display an element or video full-screen. useSlider — provides slide behavior over any HTML element. useSpeech — synthesizes speech from a text string. useVibrate — provide physical feedback using the Vibration API. useVideo — plays video, tracks its state, and exposes playback controls. useRaf — re-renders component on each requestAnimationFrame.useInterval and useHarmonicIntervalFn — re-renders component on a set interval using setInterval.useSpring — interpolates number over time according to spring dynamics.useTimeout — re-renders component after a timeout.useTimeoutFn — calls given function after a timeout. useTween — re-renders component, while tweening a number from 0 to 1. useUpdate — returns a callback, which re-renders component when called.
useAsync, useAsyncFn, and useAsyncRetry — resolves an async function.useBeforeUnload — shows browser alert when user try to reload or close the page.useCookie — provides way to read, update and delete a cookie. useCopyToClipboard — copies text to clipboard.useDebounce — debounces a function. useError — error dispatcher. useFavicon — sets favicon of the page.useLocalStorage — manages a value in localStorage.useLockBodyScroll — lock scrolling of the body element.useRafLoop — calls given function inside the RAF loop.useSessionStorage — manages a value in sessionStorage.useThrottle and useThrottleFn — throttles a function. useTitle — sets title of the page.usePermission — query permission status for browser APIs.
useEffectOnce — a modified useEffect hook that only runs once.useEvent — subscribe to events.useLifecycles — calls mount and unmount callbacks.useMountedState and useUnmountPromise — track if component is mounted.usePromise — resolves promise only while component is mounted.useLogger — logs in console as component goes through life-cycles.useMount — calls mount callbacks.useUnmount — calls unmount callbacks.useUpdateEffect — run an effect only on updates.useIsomorphicLayoutEffect — useLayoutEffect that that works on server.useDeepCompareEffect, useShallowCompareEffect, and useCustomCompareEffect
createMemo — factory of memoized hooks.createReducer — factory of reducer hooks with custom middleware.createReducerContext and createStateContext — factory of hooks for a sharing state between components.useDefault — returns the default value when state is null or undefined.useGetSet — returns state getter get() instead of raw state.useGetSetState — as if useGetSet and useSetState had a baby.useLatest — returns the latest state or propsusePrevious — returns the previous state or props. usePreviousDistinct — like usePrevious but with a predicate to determine if previous should update.useObservable — tracks latest value of an Observable.useRafState — creates setState method which only updates after requestAnimationFrame. useSetState — creates setState method which works like this.setState. useStateList — circularly iterates over an array. useToggle and useBoolean — tracks state of a boolean. useCounter and useNumber — tracks state of a number. useList useUpsertuseMap — tracks state of an object. useSet — tracks state of a Set. useQueue — implements simple queue.useStateValidator — tracks state of an object. useStateWithHistory — stores previous state values and provides handles to travel through them. useMultiStateValidator — alike the useStateValidator, but tracks multiple states at a time. useMediatedState — like the regular useState but with mediation by custom function. useFirstMountState — check if current render is first. useRendersCount — count component renders. createGlobalState — cross component shared state.useMethods — neat alternative to useReducer. useEnsuredForwardedRef and ensuredForwardRef — use a React.forwardedRef safely.
Usage — how to import.
Unlicense — public domain.
Support — add yourself to backer list below.