ahooks 3.10.0
中文
新功能与增强
useAsyncEffect支持同步返回清理函数,在依赖变化和卸载时由 React 执行清理。注意:这不支持async () => cleanup,异步函数返回的清理函数不在本次支持范围内。#2958useLocalStorageState新增getInitialValueInEffect,允许挂载后再读取存储,以避免 SSR hydration 不一致。#2906useSetState支持省略初始状态,返回状态类型为Partial<T>。#2905useAntdTable支持表单实例的validateFieldsReturnFormatValue,兼容 ProForm 的transform。
修复
useRequest修复被取消或被后续调用覆盖时的异步调用悬挂问题,并提供CancelledError/isCancelledError。#2951useRequest修复节流场景下runAsync不生效,以及ready=false时防抖前沿调用影响后续请求的问题。#2899、#2946useRequest修复默认参数场景的类型推导,并在删除缓存时清理相关定时器。#2907、#2909useInfiniteScroll修复首次loadMore期间闭包读取旧数据的问题。#2896useKeyPress修复exactMatch下修饰键的keyup事件匹配。#2944useLongPress修复 Pointer Events 支持。#2947useTheme为旧版 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 anasynccallback remains unsupported. #2958 - Add
getInitialValueInEffecttouseLocalStorageStateto defer storage reads until after mount and avoid SSR hydration mismatches. #2906 - Allow
useSetStatewithout an initial state, returningPartial<T>. #2905 - Support ProForm's
transforminuseAntdTablethroughvalidateFieldsReturnFormatValue.
Fixes
- Settle cancelled or superseded
useRequestasynchronous calls withCancelledError; exportCancelledErrorandisCancelledError. #2951 - Fix throttled
runAsynccalls and debounce leading behavior whileready=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
loadMoreinuseInfiniteScroll. #2896 - Fix modifier-key
keyupmatching withexactMatchinuseKeyPress. #2944 - Fix Pointer Events support in
useLongPress. #2947 - Fall back to legacy media query listeners in
useThemefor 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-observerdependency. #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