github alibaba/hooks v3.11.0

5 hours ago

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

Don't miss a new hooks release

NewReleases is sending notifications on new releases.