Skip to content

v3.10.0

Latest

Choose a tag to compare

@crazylxr crazylxr released this 06 Sep 02:03

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: v3.9.7...v3.10.0