You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

是否存在类似Vueuse的React集成式Hooks库?

Great question!

Absolutely—there are several polished, all-in-one React Hooks libraries that follow the same curated, dependency-light philosophy as VueUse. No more installing separate packages for every single hook; these libraries bundle a tested, well-maintained set of utilities that cover exactly the use cases you mentioned. Here are the top picks:

1. react-use

This is one of the oldest and most popular integrated React Hooks libraries, with a huge collection of hooks that map directly to the VueUse utilities you use regularly:

  • Replaces useStorage: Use useLocalStorage or useSessionStorage for persistent state tied to browser storage.
  • Replaces useToggle: The useToggle hook works exactly as you'd expect—returns a boolean state and a function to flip it.
  • Replaces computedAsync: Use useAsync or useAsyncMemo (from extended utilities) to create async-derived state that updates automatically when dependencies change.

Example usage:

import { useLocalStorage, useToggle, useAsync } from 'react-use';

// Persistent storage (like useStorage)
const [preferredTheme, setPreferredTheme] = useLocalStorage('app-theme', 'light');

// Toggle state (like useToggle)
const [isSidebarOpen, toggleSidebar] = useToggle(true);

// Async computed state (like computedAsync)
const { value: userData, loading } = useAsync(async () => {
  const res = await fetch('/api/current-user');
  return res.json();
}, []);

2. @uidotdev/usehooks

A modern, well-documented library focused on clean, TypeScript-first hooks. It’s curated to avoid bloat, with utilities that align perfectly with VueUse's practical focus:

  • Replaces useStorage: useLocalStorage handles persistent state with built-in serialization.
  • Replaces useToggle: The useToggle hook includes optional support for custom on/off values if you need more flexibility.
  • Replaces computedAsync: useAsyncMemo is designed specifically for memoized async values, mirroring computedAsync's ability to cache results and re-run when dependencies update.

Example usage:

import { useLocalStorage, useToggle, useAsyncMemo } from '@uidotdev/usehooks';

// Persistent storage
const [notificationsEnabled, setNotificationsEnabled] = useLocalStorage('notifications', true);

// Toggle with custom values
const [viewMode, toggleViewMode] = useToggle('grid', 'list');

// Async memoized state
const filteredData = useAsyncMemo(async () => {
  const rawData = await fetch('/api/dataset');
  const data = await rawData.json();
  return data.filter(item => item.isActive);
}, [], null);

3. ahooks

Developed by Alibaba, this library offers a comprehensive set of production-ready hooks with strong TypeScript support. It’s optimized for enterprise use cases but works great for any project:

  • Replaces useStorage: useLocalStorage and useSessionStorage include features like automatic JSON serialization and error handling.
  • Replaces useToggle: useToggle supports both boolean and custom value toggling, just like VueUse's version.
  • Replaces computedAsync: useAsyncMemo provides a clean way to create async-derived state with caching and dependency tracking.

Example usage:

import { useLocalStorage, useToggle, useAsyncMemo } from 'ahooks';

// Persistent user settings
const [userPrefs, setUserPrefs] = useLocalStorage('user-prefs', { fontSize: 16 });

// Toggle dark mode
const [isDarkMode, toggleDarkMode] = useToggle(false);

// Async computed data
const dashboardStats = useAsyncMemo(async () => {
  const stats = await fetchDashboardStats();
  return formatStats(stats);
}, [], { loading: null });

All three libraries are single dependencies—install once, import any hook you need. They’re all actively maintained, thoroughly tested, and designed to fill the gaps left by React’s built-in hooks, just like VueUse does for Vue.

内容的提问来源于stack exchange,提问作者tvanbeek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 19:42:38