Skip to content

v1.0.8

Choose a tag to compare

@debabin debabin released this 09 Jul 07:22
· 81 commits to main since this release
0159eba

Improve async, connection, and permission hooks

This release reworks retry handling across async hooks, adds heartbeat and delay control to WebSocket connections, and fixes permission change tracking.

Features

  • useQuery — reworked the retry logic so retry now accepts a function (failureCount, error) => boolean in addition to a boolean or number, letting you decide whether to retry based on the failure count or the error itself.
  • useQuery — added the retryDelay option to wait a given number of milliseconds before each retry, with the pending retry cancelled on abort(), refetch(), and unmount.
  • useQuery — updated refetchInterval to accept a function returning the next interval, or false to stop polling, enabling conditional polling that ends once a condition is met.
  • useWebSocket — reworked the retry logic so retry now accepts a function (failureCount, event) => boolean in addition to a boolean or number, giving full control over reconnection based on the failure count or the close event.
  • useWebSocket — added the retryDelay option to wait a given number of milliseconds before each reconnection attempt, with the pending retry cancelled on close(), open(), and unmount.
  • useWebSocket — added the heartbeat callback and the heartbeatDelay option, letting you send a keep-alive message on an interval while the connection is open, using whatever payload your protocol expects.
  • useWebSocket — added the immediately option to control whether the connection opens on mount, allowing the socket to be opened manually through open() when set to false.
  • usePermission — added the immediately option to control whether the permission is queried on mount, allowing the query to be triggered manually through query() when set to false.

Fixes

  • usePermission — the change listener is now attached to the PermissionStatus object instead of window, so state updates when the user grants or revokes the permission.

Changes

  • useWebSocket — renamed the onDisconnected callback to onClose to align with the native WebSocket close event.
  • useWebSocket — renamed the disconnected status to closed to align with the native WebSocket close event.
  • usePermission — replaced the enabled option with immediately, which only controls the query on mount rather than disabling the hook entirely.