alibaba/hooks
 Watch   
 Star   
 Fork   
28 days ago
hooks

v3.11.0

ahooks 3.11.0

中文

新功能

  • useClickAway 的第三个参数支持配置对象,新增 enabled 选项,用于控制是否绑定外部点击监听。原有事件名字符串和事件名数组调用方式保持兼容。#2984

修复

  • useInfiniteScroll 避免空页引起连续自动请求,并在加载状态更新完成后再检查是否需要继续加载。7369875、587ea88
  • useInfiniteScroll 在容器尺寸或视口变化后重新判断是否需要加载,避免初次尺寸通知触发额外请求。#2964
  • useInfiniteScroll.cancel() 清除 loadingMore,使取消后的按钮操作和滚动加载能够继续工作,同时忽略已取消请求的结果及回调。#2970
  • useCookieState 删除 Cookie 时保留配置的 path、domain 等属性,修复自定义作用域下无法删除 Cookie 的问题。#2977
  • useTheme 在服务端渲染时避免访问浏览器存储。#2983
  • useResetState 正确保留函数类型的状态值,初始化和重置时不再把该值作为状态更新函数执行。#2982
  • useDynamicList.sortList 保留 0、false 和空字符串,同时继续过滤 null 和 undefined。#2981
  • useSelections 在 itemKey 属性名或回调变化后重新计算选中映射与选中状态。#2980
  • useExternal 和 useFavicon 正确识别带查询参数或片段的资源 URL 类型,并保留元素上的原始 URL。#2979
  • useHistoryTravel 在批量设置值、前进、后退及重置后更新时保留正确的历史记录。#2978
  • useMutationObserver 使用最新回调,同时保留原生回调参数和 this,回调变化不会重建 observer。#2973

文档

  • 说明 useSessionStorageState 的 listenStorageChange 支持同页 Hook 更新及同一标签页内的同源 iframe 更新,不会跨标签页同步。#2972
  • 补充维护者发布指南,涵盖 npm、GitHub Release、文档站发布及发布后验收。

使用示例

useClickAway(onClickAway, target, {
  eventName: 'click',
  enabled: open,
});

本次发布包为 ahooks。独立包 @ahooks.js/use-url-state 保持原版本。

English

Features

  • Accept an options object as the third argument of useClickAway, with an enabled option to control whether outside-click listeners are attached. Existing event-name string and array arguments remain supported. #2984

Fixes

  • Prevent repeated automatic requests after an empty page in useInfiniteScroll, and defer bottom checks until loading state updates complete. 7369875, 587ea88
  • Recheck whether more data is needed when the scroll container or viewport changes size, without treating the initial resize notification as a resize. #2964
  • Clear loadingMore when cancelling useInfiniteScroll requests, allowing subsequent button and scroll loading while continuing to ignore cancelled responses and callbacks. #2970
  • Preserve configured Cookie attributes, including path and domain, when removing Cookies through useCookieState. #2977
  • Avoid accessing browser storage during server rendering in useTheme. #2983
  • Preserve function-valued state in useResetState instead of invoking the value as a state updater during initialization or reset. #2982
  • Preserve 0, false, and empty strings in useDynamicList.sortList, while continuing to filter out null and undefined. #2981
  • Recompute selection maps and flags when the useSelections key property or callback changes. #2980
  • Infer resource types correctly for URLs with queries or fragments in useExternal and useFavicon, preserving the original element URLs. #2979
  • Preserve history during batched updates, navigation, and updates following a reset in useHistoryTravel. #2978
  • Invoke the latest useMutationObserver callback while preserving its native arguments and receiver, without recreating the observer when the callback changes. #2973

Documentation

  • Clarify that useSessionStorageState with listenStorageChange synchronizes Hook updates on the same page and storage updates from same-origin iframes in the same tab, but not across tabs. #2972
  • Add a maintainer release guide covering npm, GitHub Releases, documentation deployment, and release verification.

Usage example

useClickAway(onClickAway, target, {
  eventName: 'click',
  enabled: open,
});

This release publishes ahooks only. The separate @ahooks.js/use-url-state package keeps its existing version.

Full changelog: v3.10.0...v3.11.0

2026-09-06 10:03:12
hooks

v3.10.0

ahooks 3.10.0

中文

新功能与增强

  • useAsyncEffect 支持同步返回清理函数,在依赖变化和卸载时由 React 执行清理。注意:这不支持 async () => cleanup,异步函数返回的清理函数不在本次支持范围内。#2958
  • useLocalStorageState 新增 getInitialValueInEffect,允许挂载后再读取存储,以避免 SSR hydration 不一致。#2906
  • useSetState 支持省略初始状态,返回状态类型为 Partial<T>。#2905
  • useAntdTable 支持表单实例的 validateFieldsReturnFormatValue,兼容 ProForm 的 transform。

修复

  • useRequest 修复被取消或被后续调用覆盖时的异步调用悬挂问题,并提供 CancelledError / isCancelledError。#2951
  • useRequest 修复节流场景下 runAsync 不生效,以及 ready=false 时防抖前沿调用影响后续请求的问题。#2899、#2946
  • useRequest 修复默认参数场景的类型推导,并在删除缓存时清理相关定时器。#2907、#2909
  • useInfiniteScroll 修复首次 loadMore 期间闭包读取旧数据的问题。#2896
  • useKeyPress 修复 exactMatch 下修饰键的 keyup 事件匹配。#2944
  • useLongPress 修复 Pointer Events 支持。#2947
  • useTheme 为旧版 Safari 提供媒体查询监听回退。#2916
  • 修复 useEventListener 显式泛型与 ref target 的兼容性,并保留非空 ref 的返回类型。#2903、#2956
  • 移除已废弃的 intersection-observer 依赖。#2904

升级注意

runAsync / refreshAsync 被取消或被新调用覆盖时,会以 CancelledError 拒绝,而不再一直保持 pending。直接调用这些异步 API 的代码应捕获异常,并用 isCancelledError 区分取消与业务错误;run / refresh 会内部处理取消。

English

Features and enhancements

  • Support synchronous cleanup functions in useAsyncEffect, with React managing cleanup on dependency changes and unmount. Returning cleanup from an async callback remains unsupported. #2958
  • Add getInitialValueInEffect to useLocalStorageState to defer storage reads until after mount and avoid SSR hydration mismatches. #2906
  • Allow useSetState without an initial state, returning Partial<T>. #2905
  • Support ProForm's transform in useAntdTable through validateFieldsReturnFormatValue.

Fixes

  • Settle cancelled or superseded useRequest asynchronous calls with CancelledError; export CancelledError and isCancelledError. #2951
  • Fix throttled runAsync calls and debounce leading behavior while ready=false. #2899, #2946
  • Fix default-parameter type inference and clear timers when request cache entries are deleted. #2907, #2909
  • Fix stale data captured during the initial loadMore in useInfiniteScroll. #2896
  • Fix modifier-key keyup matching with exactMatch in useKeyPress. #2944
  • Fix Pointer Events support in useLongPress. #2947
  • Fall back to legacy media query listeners in useTheme for older Safari versions. #2916
  • Fix explicit generic and ref target compatibility in useEventListener, and preserve non-nullable ref return types. #2903, #2956
  • Remove the deprecated intersection-observer dependency. #2904

Upgrade note

Cancelled or superseded runAsync / refreshAsync calls now reject with CancelledError instead of remaining pending. Catch errors when using these APIs directly and use isCancelledError to distinguish cancellation from service errors. run / refresh handle cancellation internally.

Full changelog: https://github.com/alibaba/hooks/compare/v3.9.7...v3.10.0

2026-03-12 13:59:57
hooks

v3.9.7

What's Changed


New Contributors

Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.6...v3.9.7

2025-10-27 12:55:41
hooks

v3.9.6

What's Changed


Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.5...v3.9.6

2025-08-31 21:57:02
hooks

v3.9.5

What's Changed


New Contributors

Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.4...v3.9.5

2025-08-22 13:08:53
hooks

v3.9.4

What's Changed

💪 chore: 测试命令改进。由 @Meet-student 贡献,详情见 PR #2835 🐞 fix: 修复 reloadAsync runAsync 负载问题。由 @Meet-student 贡献,详情见 PR #2836


💪 chore: Test command improvement. Contributed by @Meet-student, see PR #2835 for details. 🐞 fix: Fix the payload issue of reloadAsync runAsync. Contributed by @Meet-student, see PR #2836 for details.

Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.3...v3.9.4

2025-08-18 18:14:51
hooks

v3.9.3

What's Changed


New Contributors

Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.1...v3.9.3

2025-08-17 20:52:04
hooks

v3.9.1

What's Changed


New Contributors

Full Changelog: https://github.com/alibaba/hooks/compare/v3.9.0...v3.9.1

2025-06-28 21:03:05
hooks

v3.9.0

What's Changed

  • 🆕 新功能
    • 由 @li-jia-nan 贡献,在 #2776 中为 ahooks 添加了 cursor rules。
  • ⬆️ 依赖升级
    • 由 @li-jia-nan 贡献,在 #2775 支持 React 19。
  • 🐛 Bug 修复
    • 由 @Triumph-light 贡献,在 #2778 中修复了运行开发环境的问题。
    • 由 @ZephyrAndMoon 贡献,在 #2785 中修改了 useLonePress 在特殊设备、特殊情况下长按事件不触发的问题。
  • 📖 文档更新
    • 由 @cwen-jdoit 贡献,在 #2678 中更新了 useLocalStorageState 的文档。
    • 由 @superBigPotato 贡献,在 #2680 中修改了 useClickAway 文档描述,使 Target 属性支持函数。
    • 由 @xbsheng 贡献,在 #2787 中更新了 style.css 的路径。

  • 🆕 New Features
    • Contributed by @li-jia-nan, added cursor rules for ahooks in #2776.
  • ⬆️ Dependency Upgrade
    • Contributed by @li-jia-nan, upgraded the project to React 19 in #2775.
  • 🐛 Bug Fixes
    • Contributed by @Triumph-light, fixed the issue of running the development environment in #2778.
    • Contributed by @ZephyrAndMoon, modified the problem that the long - press event of useLonePress does not trigger under special devices and special circumstances in #2785.
  • 📖 Documentation Updates
    • Contributed by @cwen-jdoit, updated the documentation of useLocalStorageState in #2678.
    • Contributed by @superBigPotato, modified the documentation description of useClickAway to make the Target property support functions in #2680.
    • Contributed by @xbsheng, updated the path of style.css in #2787.

New Contributors

  • @Triumph-light made their first contribution in #2778
  • @ZephyrAndMoon made their first contribution in #2785
  • @cwen-jdoit made their first contribution in #2678
  • @superBigPotato made their first contribution in #2680

Full Changelog: https://github.com/alibaba/hooks/compare/v3.8.5...v3.9.0

2025-05-05 01:11:40
hooks

v3.8.5

What's Changed

🐛 修复问题

📘 文档改进

🛠 开发工具与维护

🔧 类型与性能优化


New Contributors

Full Changelog: https://github.com/alibaba/hooks/compare/v3.8.2...v3.8.5