v1.4.0
Add useRequest Hook
useRequest is a common hook for data fetching, supports cache, automatic refresh, and many awesome features.
- Support basic async operations state management (loading, data, error, params, etc.)
- Support many lifecycle hooks, such as onBefore, onSuccess, onError, etc.
- Support continuous automatic refresh, manual refresh, and refresh control
- Support automatic refresh when the network is reconnected, the page is focused, etc.
- Support cross-platform visibility and online judgment to control automatic refresh
- Support error retry, error retry interval, and error retry count
- Support throttle and debounce for manual refresh
- Support custom loading timeout, loading slow detection, and loading slow timeout
- Support cache, cache expiration time, and cache provider (SWR)
- Support clear cache, get cache, and mutate cache globally or locally
- Support pausable to control internal automatic behavior
- Support manual refresh, automatic refresh, and manual control refresh
🚀 Features
- New Hook
useInputCompositionto track composition state ofinputelement - by @vikiboss (5be4b) - New Hook
useLoadingSlowFnto track loading slow state - by @vikiboss (732fa) - New Hook
useReConnectto run a callback when re-connect - by @vikiboss (772ab) - New Hook
useReFocusto run a callback when re-focus - by @vikiboss (88cc9) - New Hook
useRetryFnto create a function with retry mechanism - by @vikiboss (2eceb) - createSingleLoading:
- useAsyncFn:
- Support
onMutate,onCancel,onRefreshcallbacks - by @vikiboss (a1298) - Support
onErrorcallback - by @vikiboss (072f0) - Support lifecycle callbacks & improve render performance - by @vikiboss (fe1b8)
mutate&refreshsupport params - by @vikiboss (02ff0)- Support
compareoptions to control render behavior - by @vikiboss (dfed2)
- Support
- useReactive:
🐞 Bug Fixes
- useAsyncFn: Fix race condition bug - by @vikiboss (9071e)
- useResetState: Fix returned
initialValue- by @vikiboss (5e128) - useToggle: Fix hook returned value - by @vikiboss (dd976)
🏎 Performance
View changes on GitHub
添加 useRequest 钩子
useRequest 是一个常用的数据获取钩子,支持缓存、自动刷新以及许多其他优秀特性。
- 支持基本异步操作状态管理(加载中、数据、错误、参数等)
- 支持多种生命周期钩子,例如 onBefore、onSuccess、onError 等
- 支持连续自动刷新、手动刷新和刷新控制
- 支持网络重新连接、页面聚焦等时自动刷新
- 支持跨平台可见性和在线判断来控制自动刷新
- 支持错误重试、错误重试间隔和错误重试次数
- 支持对手动刷新进行节流和防抖处理
- 支持自定义加载超时、加载缓慢检测和加载缓慢超时
- 支持缓存、缓存过期时间和缓存提供者(SWR)
- 支持全局或局部地清除缓存、获取缓存和变更缓存
- 支持暂停以控制内部自动行为
- 支持手动刷新、自动刷新和手动控制刷新
🚀 功能
- 新钩子
useInputComposition用于追踪input元素的组合状态 - 由 @vikiboss 提供 (5be4b) - 新钩子
useLoadingSlowFn用于追踪加载缓慢状态 - 由 @vikiboss 提供 (732fa) - 新钩子
useReConnect用于重新连接时运行回调函数 - 由 @vikiboss 提供 (772ab) - 新钩子
useReFocus用于重新聚焦时运行回调函数 - 由 @vikiboss 提供 (88cc9) - 新钩子
useRetryFn用于创建具有重试机制的函数 - 由 @vikiboss 提供 (2eceb) - createSingleLoading:
- useAsyncFn:
- useReactive:
🐞 修复
- useAsyncFn: 修复竞态条件 bug - 由 @vikiboss 提供 (9071e)
- useResetState: 修复返回的
initialValue- 由 @vikiboss 提供 (5e128) - useToggle: 修复钩子返回值 - 由 @vikiboss 提供 (dd976)