Releases: alibaba/hooks
Release list
v3.10.0
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
v3.9.7
What's Changed
-
🐛 Bug 修复
- 由 @linhf123 贡献,在 #2881 中为
useInfiniteScroll使用requestAnimationFrame来更新滚动位置。 - 由 @lvboda 贡献,在 #2866 中修复了
useRequest在ready=false时runAsync未立即返回的问题(无 pending 状态)。 - 由 @Arktomson 贡献,在 #2900 中为
useKeyPress添加了旧版 key 别名以提高兼容性。 - 由 @guaijie 贡献,在 #2884 中修复了
useRafInterval在执行函数内部调用clear无效的问题。 - 由 @li-jia-nan 贡献,在 #2912 中修复了相同 storage 状态导致重复渲染的问题。
- 由 @linhf123 贡献,在 #2881 中为
-
🛠️ 代码重构
- 由 @JunlinZhu-Tommy 贡献,在 #2887 中将
useUpdate中的useCallback替换为useMemoizedFn。 - 由 @li-jia-nan 贡献,在 #2868 中进行了代码优化。
- 由 @nghiepdev 贡献,在 #2859 中在
useIsomorphicLayoutEffect中使用noop替代useEffect。
- 由 @JunlinZhu-Tommy 贡献,在 #2887 中将
-
🔧 性能优化
- 由 @li-jia-nan 贡献,在 #2913 中进行了性能优化。
-
📖 文档更新
- 由 @huangkevin-apr 贡献,在 #2892 中为讨论组图片添加了
alt属性以提升可访问性。
- 由 @huangkevin-apr 贡献,在 #2892 中为讨论组图片添加了
-
🐛 Bug Fixes
- Contributed by @linhf123, used
requestAnimationFrameto update scroll position inuseInfiniteScrollin #2881. - Contributed by @lvboda, fixed the issue where
runAsyncdid not return immediately whenready=false(no pending) inuseRequestin #2866. - Contributed by @Arktomson, added legacy key aliases for compatibility in
useKeyPressin #2900. - Contributed by @guaijie, fixed the issue where calling
clearinside the execution function ofuseRafIntervaldid not take effect in #2884. - Contributed by @li-jia-nan, fixed unnecessary re-renders when the storage state remained the same in #2912.
- Contributed by @linhf123, used
-
🛠️ Code Refactoring
- Contributed by @JunlinZhu-Tommy, replaced
useCallbackwithuseMemoizedFninuseUpdatein #2887. - Contributed by @li-jia-nan, performed code optimizations in #2868.
- Contributed by @nghiepdev, used
noopinstead ofuseEffectinuseIsomorphicLayoutEffectin #2859.
- Contributed by @JunlinZhu-Tommy, replaced
-
🔧 Performance
- Contributed by @li-jia-nan, performed performance optimizations in #2913.
-
📖 Documentation Updates
- Contributed by @huangkevin-apr, added
altattributes to discussion group images for accessibility in #2892.
- Contributed by @huangkevin-apr, added
New Contributors
- @linhf123 made their first contribution in #2881
- @huangkevin-apr made their first contribution in #2892
- @lvboda made their first contribution in #2866
- @nghiepdev made their first contribution in #2859
- @JunlinZhu-Tommy made their first contribution in #2887
Full Changelog: v3.9.6...v3.9.7
v3.9.6
What's Changed
- 🔧 工程维护
- 由 @meet-student 贡献,在 #2853 中移除了 engines 中的 Node 配置。
- 由 @meet-student 贡献,在 #2857 中处理了 TypeScript lint 相关问题。
- 🔧 Engineering Maintenance
- Contributed by @meet-student, removed Node configuration from engines in #2853.
- Contributed by @meet-student, handled TypeScript lint issues in #2857.
Full Changelog: v3.9.5...v3.9.6
v3.9.5
What's Changed
- 🆕 新功能
- 由 @Arktomson 贡献,在 #2844 中将 js-cookie 的类型包放到生产依赖中。
- 🛠️ 代码重构
- 🔧 项目配置
- 📖 文档更新
- 由 @atharva6868 贡献,在 #2840 中为 useBoolean 钩子添加了新的使用示例。
- 🐛 Bug 修复
- 🆕 New Features
- Contributed by @Arktomson, added the type package of js-cookie to the production dependencies in #2844.
- 🛠️ Code Refactoring
- 🔧 Project Configuration
- 📖 Documentation Updates
- Contributed by @atharva6868, added a new usage example for the useBoolean hook in #2840.
- 🐛 Bug Fixes
New Contributors
- @BH4HPA made their first contribution in #2843
- @Arktomson made their first contribution in #2844
- @atharva6868 made their first contribution in #2840
Full Changelog: v3.9.4...v3.9.5
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: v3.9.3...v3.9.4
v3.9.3
What's Changed
- 🐞 修复:修复
useRequest在配置cachekey后,某些情况下不执行onSuccess方法的问题 (#2035) @xun-zi #2255 - 🐞 修复:修复
useMount返回 Promise 的问题 @meet-student #2833
- 🐞 Fix: Fixed the issue that the
onSuccessmethod ofuseRequestwas not executed in some cases after configuringcachekey(#2035) @xun-zi #2255 - 🐞 Fix: Fixed the problem of
useMountreturning a Promise @meet-student #2833
New Contributors
Full Changelog: v3.9.1...v3.9.3
v3.9.1
What's Changed
- 🆕 新功能
- feat: usemount 支持析构函数 by @iambimo24 in #2713
- type: useUrlState 参数类型添加数组 by @zhuleizhang in #2790
- 🔧 配置更新
- chore: 更新开发依赖 by @li-zhen-zhennnnnn in #2802
- chore: 升级依赖版本并在 CI 中使用 nodejs v20,22 by @ianzone in #2800
- 🐛 问题修复
- fix: createUseStorageState 类型未知问题 by @meet-student in #2795
- fix: 修复 useRequest 在启动两个以上轮询时,设置页面隐藏停止轮询,页面重新显示时,有请求不自动开始轮询的问题。 by @JaxonJay in #2688
- fix: 修复 useInfiniteScroll 时序竞争问题 by @duwenhan2byte in #2786
- fix: 提取集合操作的公共函数 by @maxiaokai1996 in #2661
- fix: 修复 readyState 判断问题 by @dongmucat in #2705
- fix: tsconfig 问题 by @ianzone in #2805
- 🎨 代码重构
- refactor(useTheme): 提高代码可读性 by @w2xi in #2803
- Refactor jest to vitest by 2814 by @meet-student in #2818
- 📖 文档修复
- docs: 修复 useClickAway 在 React 19 中的示例 by @li-jia-nan in #2798
- docs: 修复 useFusionTable 在 React 19 中的示例 by @li-jia-nan in #2799
- ✅ 测试更新
- test(use-url-state): 使用 vitest 进行测试 by @ianzone in #2804
- test(createDeepCompareEffect): 使用 vitest 进行测试 by @ianzone in #2807
- test(createUpdateEffect): 使用 vitest 进行测试 by @ianzone in #2810
- test(useBoolean): 使用 vitest 进行测试 by @ianzone in #2813
- test(useStorageState): 使用 vitest 进行测试 by @ianzone in #2811
- test(useAsyncEffect): 使用 vitest 进行测试 by @ianzone in #2812
- 👷 CI 相关
- 🆕 New Features
- feat: usemount supports destructor by @iambimo24 in #2713
- type: The parameter type of useUrlState adds an array by @zhuleizhang in #2790
- 🔧 Configuration Updates
- chore: Update development dependencies by @li-zhen-zhennnnnn in #2802
- chore: Upgrade dependency versions and use nodejs v20,22 in CI by @ianzone in #2800
- 🐛 Bug Fixes
- fix: Fix the unknown type issue of createUseStorageState by @meet-student in #2795
- fix: Fix the problem that when useRequest starts more than two polling requests, if the page is set to hide to stop polling, and the page is redisplayed, some requests do not automatically start polling. by @JaxonJay in #2688
- fix: Fix the timing competition issue of useInfiniteScroll by @duwenhan2byte in #2786
- fix: Extract common functions for set operations by @maxiaokai1996 in #2661
- fix: Fix the readyState judgment issue by @dongmucat in #2705
- fix: Fix tsconfig issues by @ianzone in #2805
- 🎨 Code Refactoring
- refactor(useTheme): Improve code readability by @w2xi in #2803
- Refactor jest to vitest by 2814 by @meet-student in #2818
- 📖 Documentation Fixes
- docs: Fix the useClickAway demo in React 19 by @li-jia-nan in #2798
- docs: Fix the useFusionTable demo in React 19 by @li-jia-nan in #2799
- ✅ Test Updates
- test(use-url-state): Use vitest for testing by @ianzone in #2804
- test(createDeepCompareEffect): Use vitest for testing by @ianzone in #2807
- test(createUpdateEffect): Use vitest for testing by @ianzone in #2810
- test(useBoolean): Use vitest for testing by @ianzone in #2813
- test(useStorageState): Use vitest for testing by @ianzone in #2811
- test(useAsyncEffect): Use vitest for testing by @ianzone in #2812
- 👷 CI Related
New Contributors
- @zhuleizhang made their first contribution in #2790
- @li-zhen-zhennnnnn made their first contribution in #2802
- @meet-student made their first contribution in #2795
- @w2xi made their first contribution in #2803
- @iambimo24 made their first contribution in #2713
- @JaxonJay made their first contribution in #2688
- @duwenhan2byte made their first contribution in #2786
- @maxiaokai1996 made their first contribution in #2661
- @dongmucat made their first contribution in #2705
Full Changelog: v3.9.0...v3.9.1
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的路径。
- 由 @cwen-jdoit 贡献,在 #2678 中更新了
- 🆕 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
useLonePressdoes not trigger under special devices and special circumstances in #2785.
- 📖 Documentation Updates
- Contributed by @cwen-jdoit, updated the documentation of
useLocalStorageStatein #2678. - Contributed by @superBigPotato, modified the documentation description of
useClickAwayto make theTargetproperty support functions in #2680. - Contributed by @xbsheng, updated the path of
style.cssin #2787.
- Contributed by @cwen-jdoit, updated the documentation of
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: v3.8.5...v3.9.0
v3.8.5
What's Changed
🐛 修复问题
- fix: 修复 SSR 场景下的 bug by @li-jia-nan in #2691
- fix: 修复 createUseStorageState 在 3.7.7 以上版本返回 undefined 类型的问题 by @chooin in #2681
- fix(useAntdHooks): 修复 autoRequest 与 manual: true 冲突的问题 by @yangliguo7 in #2714
- 修复变量未定义导致的 run test 报错问题 by @luckymore in #2772
📘 文档改进
- doc: 修复排版问题 by @coding-ax in #2701
- 更新中文文档 index.zh-CN.md by @jinmmd in #2745
🛠 开发工具与维护
- chore(useLatest): 修复拼写错误 by @xbsheng in #2703
- chore: 更新钉钉二维码 by @li-jia-nan in #2700
- ♻️ chore: 移除无用代码 by @Wxh16144 in #2721
- Create static.yml 文件 by @crazylxr in #2754
- chore: 更新 static ci 配置 by @crazylxr in #2755
- chore: 添加对 React 19 的 peer 依赖 by @ianzone in #2764
- Feat/static ci 相关功能开发 by @crazylxr in #2756
🔧 类型与性能优化
- Update useMemorizedFn 的返回值类型 by @XDUyhfu in #2749
- 完善 use-url-state 的 TypeScript 出参类型 by @LongHaoo in #2731
- chore(useLatest): fix spelling by @xbsheng in #2703
- chore: update dingding qr-code by @li-jia-nan in #2700
- doc: fix typography problem by @coding-ax in #2701
- Update useMemorizedFn return value type by @XDUyhfu in #2749
- fix: fix ssr bug by @li-jia-nan in #2691
- fix: createUseStorageState 3.7.7 以上版本返回 undefined 类型问题 by @chooin in #2681
- ♻️ chore: remove dead code by @Wxh16144 in #2721
- Create static.yml by @crazylxr in #2754
- chore: update static ci by @crazylxr in #2755
- Feat/static ci by @crazylxr in #2756
- Update index.zh-CN.md by @jinmmd in #2745
- feat: use-url-state 出参 typescript 完善 by @LongHaoo in #2731
- chore: add peer react 19 by @ianzone in #2764
- fix(useAntdHooks):fix autorequest with manual is true by @yangliguo7 in #2714
- 修复变量不存在导致的 run test 报错 by @luckymore in #2772
New Contributors
- @xbsheng made their first contribution in #2703
- @coding-ax made their first contribution in #2701
- @XDUyhfu made their first contribution in #2749
- @chooin made their first contribution in #2681
- @Wxh16144 made their first contribution in #2721
- @jinmmd made their first contribution in #2745
- @LongHaoo made their first contribution in #2731
- @yangliguo7 made their first contribution in #2714
- @luckymore made their first contribution in #2772
Full Changelog: v3.8.2...v3.8.5
v3.8.2
What's Changed
- 🔥 feat: add useTheme hook by @ianzone in #2617
- 🔥 feat: support for array as event parameter in useEventListener by @askwuxue in #2598
- 🔥 feat: support useInfiniteScroll scroll to top by @jaluik in #2565
- 🐛 fix: Compatible with the case where props is null in useControllableValue by @mmmml-zhao in #2636
- 🐛 fix: When manual=true, defaultParam will not populate the default values in form. by @askwuxue in #2594
- 🛠 chore: Wrap the second parameter of the return value from useSetState with useMemoriedFn. by @askwuxue in #2592
- 🛠 chore: Replace prettier with biome by @ianzone in #2629
- 🛠 chore: Update pnpm to v9 by @ianzone in #2621
- 🔥 feat: 新增 hook useTheme by @ianzone in #2617
- 🔥 feat: useEventListener 事件支持传入数组参数 by @askwuxue in #2598
- 🔥 feat: useInfiniteScroll 支持了direction, 提供向上滚动加载的支持 by @jaluik in #2565
- 🐛 fix: 兼容了 useControllableValue 的 props 为 null 的情况 by @mmmml-zhao in #2636
- 🐛 fix: useAntdTable 在 manual=true 的情况下 defaultParam 不会填充表单默认值 by @askwuxue in #2594
- 🛠 chore: 使用 useMemoriedFn 包装 useSetState 返回值中的第二个参数 by @askwuxue in #2592
- 🛠 chore: 使用 biome 替换 prettier by @ianzone in #2629
- 🛠 chore: 更新 pnpm 至 v9 by @ianzone in #2621
New Contributors
- @ianzone made their first contribution in #2621
- @mmmml-zhao made their first contribution in #2636
- @jaluik made their first contribution in #2565
Full Changelog: v3.8.1...v3.8.2