From 80ced888068ab4aba8b54895b3aa618bf3a29172 Mon Sep 17 00:00:00 2001 From: Viki Date: Thu, 20 Jun 2024 17:08:25 +0800 Subject: [PATCH] chore: use `returns` --- src/use-async-fn/index.mdx | 2 +- src/use-async-lock/index.mdx | 2 +- src/use-browser-memory/index.mdx | 2 +- src/use-clipboard-items/index.ts | 4 +- src/use-clipboard/index.ts | 4 +- src/use-device-list/index.mdx | 2 +- src/use-element-size/index.mdx | 4 +- src/use-element-size/index.ts | 4 +- src/use-getter-ref/index.mdx | 2 +- src/use-getter-ref/index.ts | 4 +- src/use-infinite-scroll/index.mdx | 2 +- src/use-infinite-scroll/index.ts | 4 +- src/use-intersection-observer/index.mdx | 4 +- src/use-intersection-observer/index.ts | 6 +- src/use-interval-fn/index.mdx | 2 +- src/use-interval/index.mdx | 4 +- src/use-interval/index.ts | 13 ++- src/use-key-modifier/index.mdx | 4 + src/use-key-modifier/index.ts | 4 +- src/use-loading-fn/index.mdx | 4 +- src/use-loading-fn/index.ts | 4 +- src/use-long-press/demo.tsx | 4 +- src/use-long-press/index.mdx | 2 +- src/use-long-press/index.ts | 6 +- src/use-manual-state-history/index.mdx | 2 +- src/use-manual-state-history/index.ts | 4 +- src/use-media-query/index.mdx | 2 +- src/use-media-query/index.ts | 4 +- src/use-memoize/index.mdx | 2 +- src/use-memoize/index.ts | 8 +- src/use-mounted/index.ts | 4 +- src/use-mouse-in-element/index.mdx | 4 +- src/use-mouse-in-element/index.ts | 11 ++- src/use-mouse-pressed/index.mdx | 2 +- src/use-mouse-pressed/index.ts | 4 +- src/use-mouse/index.mdx | 2 +- src/use-mouse/index.ts | 4 +- src/use-multi-select/demo.tsx | 26 ++--- src/use-multi-select/index.mdx | 104 ++++++++++---------- src/use-multi-select/index.ts | 123 ++++++++++++------------ src/use-mutation-observer/index.mdx | 26 +++-- src/use-mutation-observer/index.ts | 6 +- src/use-network/index.mdx | 2 +- src/use-network/index.ts | 8 +- src/use-now/index.mdx | 2 +- src/use-now/index.ts | 8 +- src/use-parallax/index.mdx | 2 +- src/use-parallax/index.ts | 4 +- src/use-parent-element/index.mdx | 2 +- src/use-parent-element/index.ts | 4 +- src/use-performance-observer/index.mdx | 4 +- src/use-performance-observer/index.ts | 6 +- src/use-permission/index.mdx | 2 +- src/use-permission/index.ts | 8 +- src/use-reporting-observer/index.mdx | 4 +- src/use-reporting-observer/index.ts | 6 +- src/use-resize-observer/index.mdx | 4 +- src/use-resize-observer/index.ts | 6 +- src/use-script-tag/index.mdx | 2 +- src/use-script-tag/index.ts | 4 +- src/use-scroll-lock/index.mdx | 2 +- src/use-scroll-lock/index.ts | 4 +- src/use-scroll/index.mdx | 2 +- src/use-scroll/index.ts | 4 +- src/use-signal-state/index.mdx | 2 +- src/use-signal-state/index.ts | 4 +- src/use-spring-value/index.mdx | 2 +- src/use-spring-value/index.ts | 4 +- src/use-state-history/index.ts | 8 +- src/use-stepper/index.mdx | 2 +- src/use-stepper/index.ts | 4 +- src/use-style-tag/index.mdx | 2 +- src/use-style-tag/index.ts | 4 +- src/use-supported/index.mdx | 4 +- src/use-text-direction/index.mdx | 2 +- src/use-text-direction/index.ts | 4 +- src/use-text-selection/index.mdx | 2 +- src/use-text-selection/index.ts | 4 +- src/use-time-ago/index.mdx | 2 +- src/use-time-ago/index.ts | 6 +- src/use-timeout/index.mdx | 2 +- src/use-timeout/index.ts | 6 +- src/use-toggle/index.ts | 12 +-- src/use-unmounted/index.ts | 4 +- src/use-url-search-params/index.mdx | 2 +- src/use-url-search-params/index.ts | 4 +- src/use-user-idle/index.mdx | 2 +- src/use-user-idle/index.ts | 4 +- src/use-user-media/index.mdx | 2 +- src/use-user-media/index.ts | 4 +- src/use-web-observer/index.mdx | 12 +-- src/use-web-observer/index.ts | 12 +-- src/use-window-scroll/index.mdx | 2 +- src/use-window-scroll/index.ts | 4 +- src/use-window-size/index.mdx | 2 +- src/use-window-size/index.ts | 4 +- src/utils/basic.ts | 4 +- 97 files changed, 335 insertions(+), 324 deletions(-) diff --git a/src/use-async-fn/index.mdx b/src/use-async-fn/index.mdx index 476db7b7..d8f0f436 100644 --- a/src/use-async-fn/index.mdx +++ b/src/use-async-fn/index.mdx @@ -53,7 +53,7 @@ export type UseAsyncFnOptions = { ### Returns ```tsx -export type UseAsyncFnReturn = { +export type UseAsyncFnReturns = { /** * a function to run the async function */ diff --git a/src/use-async-lock/index.mdx b/src/use-async-lock/index.mdx index 0316299c..fc063e80 100644 --- a/src/use-async-lock/index.mdx +++ b/src/use-async-lock/index.mdx @@ -46,7 +46,7 @@ A function that will be called when the function is locked and is called again. A function that can be used to ensure that **only one is running at a time**, return a promise that resolves the return value of the async function or the return value of the invalid operation callback function. ```tsx -export type UseAsyncLockReturn = ( +export type UseAsyncLockReturns = ( ...args: Parameters ) => R extends undefined ? Promise> | undefined> diff --git a/src/use-browser-memory/index.mdx b/src/use-browser-memory/index.mdx index 82406896..33a622a7 100644 --- a/src/use-browser-memory/index.mdx +++ b/src/use-browser-memory/index.mdx @@ -42,7 +42,7 @@ export type UseBrowserMemoryOptions = UseIntervalFnOptions & { ### Returns ```tsx -export type UseBrowserMemoryReturn = { +export type UseBrowserMemoryReturns = { /** * The timestamp when the memory info was last updated. */ diff --git a/src/use-clipboard-items/index.ts b/src/use-clipboard-items/index.ts index 5bfb9b62..69a5c912 100644 --- a/src/use-clipboard-items/index.ts +++ b/src/use-clipboard-items/index.ts @@ -6,7 +6,7 @@ import { useSupported } from '../use-supported' import { useTimeoutFn } from '../use-timeout-fn' import { useLatest } from '../use-latest' -import type { UsePermissionReturn } from '../use-permission' +import type { UsePermissionReturns } from '../use-permission' export interface UseClipboardItemsOptions { /** @@ -50,7 +50,7 @@ export interface UseClipboardItemsReturns { clear(): void } -function isAllowed(status: UsePermissionReturn) { +function isAllowed(status: UsePermissionReturns) { return status.current && ['granted', 'prompt'].includes(status.current) } diff --git a/src/use-clipboard/index.ts b/src/use-clipboard/index.ts index 9c61d9e2..2e77834e 100644 --- a/src/use-clipboard/index.ts +++ b/src/use-clipboard/index.ts @@ -7,7 +7,7 @@ import { useSupported } from '../use-supported' import { useTimeoutFn } from '../use-timeout-fn' import { unwrapGettable } from '../utils/unwrap' -import type { UsePermissionReturn } from '../use-permission' +import type { UsePermissionReturns } from '../use-permission' import type { Gettable } from '../utils/basic' export interface UseClipboardOptions { @@ -123,6 +123,6 @@ function legacyRead() { return document.getSelection()?.toString() ?? '' } -function isAllowed(status: UsePermissionReturn) { +function isAllowed(status: UsePermissionReturns) { return status.current && ['granted', 'prompt'].includes(status.current) } diff --git a/src/use-device-list/index.mdx b/src/use-device-list/index.mdx index 35f849de..52f6e26a 100644 --- a/src/use-device-list/index.mdx +++ b/src/use-device-list/index.mdx @@ -57,7 +57,7 @@ export type UseDeviceListOptions = { ### Returns ```tsx -export type UseDeviceListReturn = { +export type UseDeviceListReturns = { /** * List of all devices */ diff --git a/src/use-element-size/index.mdx b/src/use-element-size/index.mdx index 486e194a..4223703d 100644 --- a/src/use-element-size/index.mdx +++ b/src/use-element-size/index.mdx @@ -30,7 +30,7 @@ import { Source } from '@/components' ## API ```tsx -const { width, height, ...useResizeObserverReturn } = useElementSize(elementTarget, defaultValue, options) +const { width, height, ...useResizeObserverReturns } = useElementSize(elementTarget, defaultValue, options) ``` ### ElementTarget @@ -63,5 +63,5 @@ Options of `useResizeObserver`, see [useResizeObserver#options](/reference/use-r Returns of `useResizeObserver`, see [useResizeObserver#returns](/reference/use-resize-observer/#returns) for more details. ```tsx -export type UseElementSizeReturns = ElementSize & UseResizeObserverReturn +export type UseElementSizeReturns = ElementSize & UseResizeObserverReturns ``` diff --git a/src/use-element-size/index.ts b/src/use-element-size/index.ts index b1e99b28..df2b51d3 100644 --- a/src/use-element-size/index.ts +++ b/src/use-element-size/index.ts @@ -2,7 +2,7 @@ import { useResizeObserver } from '../use-resize-observer' import { useSafeState } from '../use-safe-state' import { normalizeElement, useTargetElement } from '../use-target-element' -import type { UseResizeObserverOptions, UseResizeObserverReturn } from '../use-resize-observer' +import type { UseResizeObserverOptions, UseResizeObserverReturns } from '../use-resize-observer' import type { ElementTarget } from '../use-target-element' export interface ElementSize { @@ -16,7 +16,7 @@ export interface ElementSize { height: number } -export interface UseElementSizeReturns extends ElementSize, UseResizeObserverReturn {} +export interface UseElementSizeReturns extends ElementSize, UseResizeObserverReturns {} export function useElementSize( target: ElementTarget, diff --git a/src/use-getter-ref/index.mdx b/src/use-getter-ref/index.mdx index 0c4a5819..aab2f65c 100644 --- a/src/use-getter-ref/index.mdx +++ b/src/use-getter-ref/index.mdx @@ -42,7 +42,7 @@ Initial value of the ref. ### Returns ```tsx -export type UseGetterRefReturn = [ +export type UseGetterRefReturns = [ /** * A mutable ref object that can be used to store a value. */ diff --git a/src/use-getter-ref/index.ts b/src/use-getter-ref/index.ts index ebd0f1c4..b4062bfb 100644 --- a/src/use-getter-ref/index.ts +++ b/src/use-getter-ref/index.ts @@ -1,7 +1,7 @@ import { useRef } from 'react' import { useStableFn } from '../use-stable-fn' -export type UseGetterRefReturn = [ +export type UseGetterRefReturns = [ /** * A mutable ref object that can be used to store a value. */ @@ -12,7 +12,7 @@ export type UseGetterRefReturn = [ getter: () => T, ] -export function useGetterRef(initial: T): UseGetterRefReturn { +export function useGetterRef(initial: T): UseGetterRefReturns { const ref = useRef(initial) const getter = useStableFn(() => ref.current) return [ref, getter] as const diff --git a/src/use-infinite-scroll/index.mdx b/src/use-infinite-scroll/index.mdx index 7a8a17a6..eca2e547 100644 --- a/src/use-infinite-scroll/index.mdx +++ b/src/use-infinite-scroll/index.mdx @@ -73,7 +73,7 @@ export type UseInfiniteScrollOptions = UseS ### Returns ```tsx -export type UseInfiniteScrollReturn = { +export type UseInfiniteScrollReturns = { /** * loading state */ diff --git a/src/use-infinite-scroll/index.ts b/src/use-infinite-scroll/index.ts index 2a2c0a0e..5dd780f6 100644 --- a/src/use-infinite-scroll/index.ts +++ b/src/use-infinite-scroll/index.ts @@ -40,7 +40,7 @@ export interface UseInfiniteScrollOptions extends UseScrollOptions { canLoadMore?: (previousReturn: R | undefined) => boolean } -export interface UseInfiniteScrollReturn { +export interface UseInfiniteScrollReturns { /** * loading state */ @@ -60,7 +60,7 @@ export function useInfiniteScroll( target: ElementTarget, onLoadMore: (previousReturn: R | undefined) => R | Promise, options: UseInfiniteScrollOptions = {}, -): UseInfiniteScrollReturn { +): UseInfiniteScrollReturns { const { direction = 'bottom', immediate = true, interval = 100, canLoadMore = () => true, distance = 100 } = options const el = useTargetElement(target) diff --git a/src/use-intersection-observer/index.mdx b/src/use-intersection-observer/index.mdx index 4f3ca26e..bf820a2b 100644 --- a/src/use-intersection-observer/index.mdx +++ b/src/use-intersection-observer/index.mdx @@ -70,7 +70,7 @@ export type UseIntersectionObserverOptions = UseWebObserverOptions & Intersectio ```tsx -export interface UseWebObserverReturn extends Pausable { +export interface UseWebObserverReturns extends Pausable { /** * ref that holds the observer instance */ @@ -81,5 +81,5 @@ export interface UseWebObserverReturn extends Pausable { isSupported: boolean } -export type UseIntersectionObserverReturn = UseWebObserverReturn +export type UseIntersectionObserverReturns = UseWebObserverReturns ``` diff --git a/src/use-intersection-observer/index.ts b/src/use-intersection-observer/index.ts index 73df4528..d4a0a10d 100644 --- a/src/use-intersection-observer/index.ts +++ b/src/use-intersection-observer/index.ts @@ -1,17 +1,17 @@ import { useWebObserver } from '../use-web-observer' import type { ElementTarget } from '../use-target-element' -import type { UseWebObserverOptions, UseWebObserverReturn } from '../use-web-observer' +import type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer' import type { Arrayable } from '../utils/basic' export interface UseIntersectionObserverOptions extends UseWebObserverOptions, IntersectionObserverInit {} -export interface UseIntersectionObserverReturn extends UseWebObserverReturn {} +export interface UseIntersectionObserverReturns extends UseWebObserverReturns {} export function useIntersectionObserver( target: Arrayable, callback: IntersectionObserverCallback, options: UseIntersectionObserverOptions = {}, -): UseIntersectionObserverReturn { +): UseIntersectionObserverReturns { const { immediate = true, ...initOptions } = options return useWebObserver('IntersectionObserver', target, callback, { immediate }, initOptions) diff --git a/src/use-interval-fn/index.mdx b/src/use-interval-fn/index.mdx index fe83ec69..6fc02737 100644 --- a/src/use-interval-fn/index.mdx +++ b/src/use-interval-fn/index.mdx @@ -65,5 +65,5 @@ import { Tip } from '@/components' ```tsx -export type UseIntervalFnReturn = Pausable +export type UseIntervalFnReturns = Pausable ``` diff --git a/src/use-interval/index.mdx b/src/use-interval/index.mdx index 26fe1d70..74c4f1bb 100644 --- a/src/use-interval/index.mdx +++ b/src/use-interval/index.mdx @@ -76,7 +76,7 @@ export interface UseIntervalAction extends UseCounterReturnsAction, Pausable { reset: (count?: number) => void } -export type UseIntervalWithControlsReturn = [ +export type UseIntervalWithControlsReturns = [ /** * Current count */ @@ -87,5 +87,5 @@ export type UseIntervalWithControlsReturn = [ UseIntervalAction, ] -export type UseIntervalReturn = Controls extends true ? UseIntervalWithControlsReturn : number +export type UseIntervalReturns = Controls extends true ? UseIntervalWithControlsReturns : number ``` diff --git a/src/use-interval/index.ts b/src/use-interval/index.ts index a1fb88ca..868b297b 100644 --- a/src/use-interval/index.ts +++ b/src/use-interval/index.ts @@ -32,7 +32,7 @@ export interface UseIntervalAction extends UseCounterReturnsAction, Pausable { reset: (count?: number) => void } -export type UseIntervalWithControlsReturn = [ +export type UseIntervalWithControlsReturns = [ /** * Current count */ @@ -43,13 +43,18 @@ export type UseIntervalWithControlsReturn = [ UseIntervalAction, ] -export type UseIntervalReturn = Controls extends true ? UseIntervalWithControlsReturn : number +export type UseIntervalReturns = Controls extends true + ? UseIntervalWithControlsReturns + : number export function useInterval( interval?: UseIntervalFnInterval, options?: UseIntervalOptions, -): UseIntervalReturn -export function useInterval(interval: UseIntervalFnInterval, options: UseIntervalOptions): UseIntervalReturn +): UseIntervalReturns +export function useInterval( + interval: UseIntervalFnInterval, + options: UseIntervalOptions, +): UseIntervalReturns export function useInterval(interval: UseIntervalFnInterval = 1000, options: UseIntervalOptions = {}) { const { controls: exposeControls = false, immediate = true, callback } = options const [count, actions] = useCounter(0) diff --git a/src/use-key-modifier/index.mdx b/src/use-key-modifier/index.mdx index db74757b..141dcabd 100644 --- a/src/use-key-modifier/index.mdx +++ b/src/use-key-modifier/index.mdx @@ -71,3 +71,7 @@ export type UseModifierOptions = { ### Returns `boolean | null`, `boolean` indicates if the key modifier is pressed, `null` is means that the events not yet fired. + +```tsx +export type UseKeyModifierReturns = Initial extends boolean ? boolean : boolean | null +``` diff --git a/src/use-key-modifier/index.ts b/src/use-key-modifier/index.ts index 61d4b497..8b2f7f85 100644 --- a/src/use-key-modifier/index.ts +++ b/src/use-key-modifier/index.ts @@ -35,12 +35,12 @@ export interface UseModifierOptions { initial?: Initial } -export type UseKeyModifierReturn = Initial extends boolean ? boolean : boolean | null +export type UseKeyModifierReturns = Initial extends boolean ? boolean : boolean | null export function useKeyModifier( modifier: KeyModifier, options: UseModifierOptions = {}, -): UseKeyModifierReturn { +): UseKeyModifierReturns { const { events = defaultEvents, initial = null } = options const [state, setState] = useSafeState(initial as boolean) diff --git a/src/use-loading-fn/index.mdx b/src/use-loading-fn/index.mdx index ba939f36..503a64fc 100644 --- a/src/use-loading-fn/index.mdx +++ b/src/use-loading-fn/index.mdx @@ -29,6 +29,4 @@ import { Source } from '@/components' ## API -```tsx -useLoadingFn(fn) -``` +See [useAsyncFn#api](/reference/use-async-fn/#api) for more details. diff --git a/src/use-loading-fn/index.ts b/src/use-loading-fn/index.ts index 1c582a9d..df2e6762 100644 --- a/src/use-loading-fn/index.ts +++ b/src/use-loading-fn/index.ts @@ -4,8 +4,8 @@ import type { UseAsyncFnOptions, UseAsyncFnReturns } from '../use-async-fn' import type { AnyFunc } from '../utils/basic' export interface UseLoadingFnOptions extends UseAsyncFnOptions {} -export interface UseLoadingFnReturn extends UseAsyncFnReturns {} +export interface UseLoadingFnReturns extends UseAsyncFnReturns {} -export function useLoadingFn(fn: T, options: UseLoadingFnOptions = {}): UseLoadingFnReturn { +export function useLoadingFn(fn: T, options: UseLoadingFnOptions = {}): UseLoadingFnReturns { return useAsyncFn(fn, options) } diff --git a/src/use-long-press/demo.tsx b/src/use-long-press/demo.tsx index adf828e4..ec68bae5 100644 --- a/src/use-long-press/demo.tsx +++ b/src/use-long-press/demo.tsx @@ -1,9 +1,9 @@ import { Card } from '@/components' import { useLongPress } from '@shined/react-use' -import type { UseLongPressReturn } from '@shined/react-use' +import type { UseLongPressReturns } from '@shined/react-use' -const getTipAndBgColor = (lp: UseLongPressReturn) => { +const getTipAndBgColor = (lp: UseLongPressReturns) => { if (lp.isMeetThreshold) return { tip: 'Meet threshold 😅', bgColor: 'bg-red/80' } if (lp.isLongPressed) return { tip: 'Long pressed 👍', bgColor: 'bg-primary/80' } if (lp.isPressed) return { tip: 'Pressed, hold on 😊', bgColor: 'bg-blue/80' } diff --git a/src/use-long-press/index.mdx b/src/use-long-press/index.mdx index 4b772abf..7ab511ea 100644 --- a/src/use-long-press/index.mdx +++ b/src/use-long-press/index.mdx @@ -93,7 +93,7 @@ export interface UseLongPressOptions { ### Returns ```tsx -export type UseLongPressReturn = { +export type UseLongPressReturns = { /** * Whether the element is pressed */ diff --git a/src/use-long-press/index.ts b/src/use-long-press/index.ts index 3c5b3136..ab1d3016 100644 --- a/src/use-long-press/index.ts +++ b/src/use-long-press/index.ts @@ -54,7 +54,7 @@ export interface UseLongPressOptions { distanceThreshold?: number | false } -const defaultFalsyState: Pick = { +const defaultFalsyState: Pick = { isPressed: false, isLongPressed: false, isMeetThreshold: false, @@ -62,7 +62,7 @@ const defaultFalsyState: Pick void -export interface UseLongPressReturn { +export interface UseLongPressReturns { /** * Whether the element is pressed */ @@ -85,7 +85,7 @@ export function useLongPress( target: ElementTarget, handler?: UseLongPressHandler, options?: UseLongPressOptions, -): UseLongPressReturn { +): UseLongPressReturns { const el = useTargetElement(target) const timeout = useRef(null) const posStart = useRef() diff --git a/src/use-manual-state-history/index.mdx b/src/use-manual-state-history/index.mdx index 0a7acd2d..11e57b69 100644 --- a/src/use-manual-state-history/index.mdx +++ b/src/use-manual-state-history/index.mdx @@ -98,7 +98,7 @@ export type UseRefHistoryRecord = { timestamp: number } -export type UseManualStateHistoryReturn = { +export type UseManualStateHistoryReturns = { /** * The source state */ diff --git a/src/use-manual-state-history/index.ts b/src/use-manual-state-history/index.ts index 9485a170..15875344 100644 --- a/src/use-manual-state-history/index.ts +++ b/src/use-manual-state-history/index.ts @@ -60,7 +60,7 @@ export interface UseManualStateHistoryOptions { parse?: (v: Serialized) => Raw } -export interface UseManualStateHistoryReturn { +export interface UseManualStateHistoryReturns { /** * The source state */ @@ -122,7 +122,7 @@ function defaultParse(clone?: boolean | CloneFn) { export function useManualStateHistory( source: Raw, options: UseManualStateHistoryOptions = {}, -): UseManualStateHistoryReturn { +): UseManualStateHistoryReturns { const { clone = false, dump = defaultDump(clone), diff --git a/src/use-media-query/index.mdx b/src/use-media-query/index.mdx index 03b3de85..08ef7d3a 100644 --- a/src/use-media-query/index.mdx +++ b/src/use-media-query/index.mdx @@ -53,5 +53,5 @@ If `queryString` is a `string`, returns a `boolean` value that indicates whether If `queryString` is an array, returns an array of `boolean` values that indicate whether the media queries match. ```tsx -export type UseMediaQueryReturn = R extends T[] ? boolean[] : boolean +export type UseMediaQueryReturns = R extends T[] ? boolean[] : boolean ``` diff --git a/src/use-media-query/index.ts b/src/use-media-query/index.ts index 8785065e..3cf9c186 100644 --- a/src/use-media-query/index.ts +++ b/src/use-media-query/index.ts @@ -8,7 +8,7 @@ import type { Arrayable, Gettable } from '../utils/basic' export type UseMediaQueryType = Gettable export type MediaQueryChangeListener = (this: MediaQueryList, ev: MediaQueryListEvent) => void -export type UseMediaQueryReturn = R extends T[] ? boolean[] : boolean +export type UseMediaQueryReturns = R extends T[] ? boolean[] : boolean export interface UseMediaQueryOptions extends AddEventListenerOptions {} @@ -18,7 +18,7 @@ export interface UseMediaQueryOptions extends AddEventListenerOptions {} export function useMediaQuery = Arrayable>( query: R, options: UseMediaQueryOptions = {}, -): UseMediaQueryReturn { +): UseMediaQueryReturns { const { ...addEventListenerOptions } = options const queryStrings = unwrapArrayable(query).filter(Boolean).map(unwrapGettable) const mediaQueries = useRef<(MediaQueryList & { handler?: MediaQueryChangeListener })[]>([]) diff --git a/src/use-memoize/index.mdx b/src/use-memoize/index.mdx index 381bd81a..9f4e8979 100644 --- a/src/use-memoize/index.mdx +++ b/src/use-memoize/index.mdx @@ -67,7 +67,7 @@ export type UseMemoizeOptions = { ### Returns ```tsx -export type UseMemoizeReturn = { +export type UseMemoizeReturns = { /** * Memoized function */ diff --git a/src/use-memoize/index.ts b/src/use-memoize/index.ts index 7feed106..3e52b990 100644 --- a/src/use-memoize/index.ts +++ b/src/use-memoize/index.ts @@ -27,7 +27,7 @@ export interface UseMemoizeOptions { cache?: UseMemoizeCache } -export interface UseMemoizeReturn { +export interface UseMemoizeReturns { /** * Memoized function */ @@ -57,7 +57,7 @@ export interface UseMemoizeReturn { export function useMemoize( resolver: (...args: Args) => Result, options: UseMemoizeOptions = {}, -): UseMemoizeReturn { +): UseMemoizeReturns { const cache = useCreation((): UseMemoizeCache => { if (options?.cache) return options.cache return new Map() @@ -83,7 +83,7 @@ export function useMemoize( const clearData = useStableFn(() => cache.clear()) - const memoized: Partial> = (...args: Args): Result => { + const memoized: Partial> = (...args: Args): Result => { const key = getKey(...args) if (latest.current.cache.has(key)) { return latest.current.cache.get(key) as Result @@ -97,5 +97,5 @@ export function useMemoize( memoized.getKey = getKey memoized.cache = cache - return memoized as UseMemoizeReturn + return memoized as UseMemoizeReturns } diff --git a/src/use-mounted/index.ts b/src/use-mounted/index.ts index afecd09c..e8450993 100644 --- a/src/use-mounted/index.ts +++ b/src/use-mounted/index.ts @@ -2,12 +2,10 @@ import { useRef } from 'react' import { useEffectOnce } from '../use-effect-once' import { useStableFn } from '../use-stable-fn' -export type UseMountedReturn = () => boolean - /** * Returns a function that returns whether the component is mounted. */ -export function useMounted(): UseMountedReturn { +export function useMounted(): () => boolean { const mountedRef = useRef(false) useEffectOnce(() => { diff --git a/src/use-mouse-in-element/index.mdx b/src/use-mouse-in-element/index.mdx index 94ec023d..d61d8442 100644 --- a/src/use-mouse-in-element/index.mdx +++ b/src/use-mouse-in-element/index.mdx @@ -48,7 +48,7 @@ export type MouseInElementOptions = UseMouseOptions & { handleOutside?: boolean ```tsx -export type UseMouseInElementReturn = Pausable & { +export type UseMouseInElementReturns = Pausable & { /** * Whether the mouse is outside the element */ @@ -84,6 +84,6 @@ export type UseMouseInElementReturn = Pausable & { /** * The mouse state */ - mouse: UseMouseReturn + mouse: UseMouseReturns } ``` diff --git a/src/use-mouse-in-element/index.ts b/src/use-mouse-in-element/index.ts index 668650b2..4cc0342e 100644 --- a/src/use-mouse-in-element/index.ts +++ b/src/use-mouse-in-element/index.ts @@ -6,7 +6,7 @@ import { useSetState } from '../use-set-state' import { useStableFn } from '../use-stable-fn' import { useTargetElement } from '../use-target-element' -import type { UseMouseOptions, UseMouseReturn } from '../use-mouse' +import type { UseMouseOptions, UseMouseReturns } from '../use-mouse' import type { Pausable } from '../use-pausable' import type { ElementTarget } from '../use-target-element' @@ -14,7 +14,7 @@ export interface MouseInElementOptions extends UseMouseOptions { handleOutside?: boolean } -export interface UseMouseInElementReturn extends Pausable { +export interface UseMouseInElementReturns extends Pausable { /** * Whether the mouse is outside the element */ @@ -50,10 +50,13 @@ export interface UseMouseInElementReturn extends Pausable { /** * The mouse state */ - mouse: UseMouseReturn + mouse: UseMouseReturns } -export function useMouseInElement(target: ElementTarget, options: MouseInElementOptions = {}): UseMouseInElementReturn { +export function useMouseInElement( + target: ElementTarget, + options: MouseInElementOptions = {}, +): UseMouseInElementReturns { const { handleOutside = true } = options const mType = options.type || 'page' diff --git a/src/use-mouse-pressed/index.mdx b/src/use-mouse-pressed/index.mdx index 5842be25..db1a70f9 100644 --- a/src/use-mouse-pressed/index.mdx +++ b/src/use-mouse-pressed/index.mdx @@ -79,7 +79,7 @@ export type MousePressedOptions = { ### Returns ```tsx -export type UseMousePressedReturn = { +export type UseMousePressedReturns = { /** * Whether the mouse is pressed */ diff --git a/src/use-mouse-pressed/index.ts b/src/use-mouse-pressed/index.ts index c21dc1d6..c90e029b 100644 --- a/src/use-mouse-pressed/index.ts +++ b/src/use-mouse-pressed/index.ts @@ -34,7 +34,7 @@ export interface MousePressedOptions { initialValue?: boolean } -export interface UseMousePressedReturn { +export interface UseMousePressedReturns { /** * Whether the mouse is pressed */ @@ -48,7 +48,7 @@ export interface UseMousePressedReturn { export function useMousePressed( target: ElementTarget | (() => Window) | (() => Document) = () => window, options: MousePressedOptions = {}, -) { +): UseMousePressedReturns { const { touch = true, drag = true, capture = false, initialValue = false } = options const el = useTargetElement(target) diff --git a/src/use-mouse/index.mdx b/src/use-mouse/index.mdx index 67076827..3393b1c7 100644 --- a/src/use-mouse/index.mdx +++ b/src/use-mouse/index.mdx @@ -100,7 +100,7 @@ export type Position = { y: number } -export type UseMouseReturn = Position & +export type UseMouseReturns = Position & Pausable & { /** * mouse event position. diff --git a/src/use-mouse/index.ts b/src/use-mouse/index.ts index c61da335..97d49065 100644 --- a/src/use-mouse/index.ts +++ b/src/use-mouse/index.ts @@ -70,7 +70,7 @@ const UseMouseBuiltinExtractors: Record

Choose your favorite fruits

{list.map((item) => { - const isSelected = multiSelect.isItemSelected(item) + const isSelected = actions.isItemSelected(item) return ( ) })}
- - - - + + + + - - - - - + + + + + - + ) diff --git a/src/use-multi-select/index.mdx b/src/use-multi-select/index.mdx index 613215ef..16589fb4 100644 --- a/src/use-multi-select/index.mdx +++ b/src/use-multi-select/index.mdx @@ -44,55 +44,59 @@ A list of items that are selected by default.
Show Type Definitions ```tsx -export type UseMultiSelectReturn = { - /** - * The selected items - */ - selected: T[] - /** - * Whether none of the items are selected - */ - isNoneSelected: boolean - /** - * Whether all of the items are selected - */ - isAllSelected: boolean - /** - * Whether some of the items are selected - */ - isPartiallySelected: boolean - /** - * Whether the item is selected - */ - isItemSelected: (item: T) => boolean - /** - * Set the selected items - */ - setSelected: ReactSetState - /** - * Select the item - */ - select: (item: T) => void - /** - * Select all items - */ - selectAll(): void - /** - * Unselect the item - */ - unSelect: (item: T) => void - /** - * Unselect all items - */ - unSelectAll(): void - /** - * Toggle the item - */ - toggle: (item: T) => void - /** - * Toggle all items - */ - toggleAll(): void -} +export type UseMultiSelectReturns = readonly [ + { + /** + * The selected items + */ + selected: T[] + /** + * Whether none of the items are selected + */ + isNoneSelected: boolean + /** + * Whether all of the items are selected + */ + isAllSelected: boolean + /** + * Whether some of the items are selected + */ + isPartiallySelected: boolean + }, + { + /** + * Whether the item is selected + */ + isItemSelected: (item: T) => boolean + /** + * Set the selected items + */ + setSelected: ReactSetState + /** + * Select the item + */ + select: (item: T) => void + /** + * Select all items + */ + selectAll(): void + /** + * Unselect the item + */ + unSelect: (item: T) => void + /** + * Unselect all items + */ + unSelectAll(): void + /** + * Toggle the item + */ + toggle: (item: T) => void + /** + * Toggle all items + */ + toggleAll(): void + }, +] ```
diff --git a/src/use-multi-select/index.ts b/src/use-multi-select/index.ts index 75b2e1f6..531ccdd9 100644 --- a/src/use-multi-select/index.ts +++ b/src/use-multi-select/index.ts @@ -6,58 +6,62 @@ import { useStableFn } from '../use-stable-fn' import type { ReactSetState } from '../use-safe-state' -export interface UseMultiSelectReturn { - /** - * The selected items - */ - selected: T[] - /** - * Whether none of the items are selected - */ - isNoneSelected: boolean - /** - * Whether all of the items are selected - */ - isAllSelected: boolean - /** - * Whether some of the items are selected - */ - isPartiallySelected: boolean - /** - * Whether the item is selected - */ - isItemSelected: (item: T) => boolean - /** - * Set the selected items - */ - setSelected: ReactSetState - /** - * Select the item - */ - select: (item: T) => void - /** - * Select all items - */ - selectAll(): void - /** - * Unselect the item - */ - unSelect: (item: T) => void - /** - * Unselect all items - */ - unSelectAll(): void - /** - * Toggle the item - */ - toggle: (item: T) => void - /** - * Toggle all items - */ - toggleAll(): void -} - -export function useMultiSelect(items: T[], defaultSelected: T[] = []): UseMultiSelectReturn { +export type UseMultiSelectReturns = readonly [ + { + /** + * The selected items + */ + selected: T[] + /** + * Whether none of the items are selected + */ + isNoneSelected: boolean + /** + * Whether all of the items are selected + */ + isAllSelected: boolean + /** + * Whether some of the items are selected + */ + isPartiallySelected: boolean + }, + { + /** + * Whether the item is selected + */ + isItemSelected: (item: T) => boolean + /** + * Set the selected items + */ + setSelected: ReactSetState + /** + * Select the item + */ + select: (item: T) => void + /** + * Select all items + */ + selectAll(): void + /** + * Unselect the item + */ + unSelect: (item: T) => void + /** + * Unselect all items + */ + unSelectAll(): void + /** + * Toggle the item + */ + toggle: (item: T) => void + /** + * Toggle all items + */ + toggleAll(): void + }, +] + +export function useMultiSelect(items: T[], defaultSelected: T[] = []): UseMultiSelectReturns { const [selected, setSelected] = useSafeState(defaultSelected) const selectedSet = useCreation(() => new Set(selected), [selected]) const latestSet = useLatest(selectedSet) @@ -107,22 +111,23 @@ export function useMultiSelect(items: T[], defaultSelected: T[] = []): UseMul const isItemSelected = useStableFn((item: T) => latestSet.current.has(item)) - return { + const state = { selected, isNoneSelected, isAllSelected, isPartiallySelected, + } + const actions = useCreation(() => ({ isItemSelected, - setSelected, - select, selectAll, - + setSelected, + toggle, + toggleAll, unSelect, unSelectAll, + })) - toggle, - toggleAll, - } + return [state, actions] as const } diff --git a/src/use-mutation-observer/index.mdx b/src/use-mutation-observer/index.mdx index 607a8209..6493a869 100644 --- a/src/use-mutation-observer/index.mdx +++ b/src/use-mutation-observer/index.mdx @@ -48,6 +48,15 @@ type MutationCallback = (mutations: MutationRecord[], observer: MutationObserver ### Options ```tsx +export interface UseWebObserverOptions { + /** + * Start the observer immediate after calling this function + * + * @defaultValue true + */ + immediate?: boolean +} + type MutationObserverInit = { childList?: boolean attributes?: boolean @@ -58,18 +67,7 @@ type MutationObserverInit = { attributeFilter?: string[] } -export type UseWebObserverReturn = Pausable & { - /** - * ref that holds the observer instance - */ - observerRef: MutableRefObject - /** - * Check if the observer is supported in the current environment - */ - isSupported: boolean -} - -export type UseMutationObserverReturn = UseWebObserverReturn +export interface UseMutationObserverOptions extends UseWebObserverOptions, MutationObserverInit {} ``` ### Returns @@ -77,7 +75,7 @@ export type UseMutationObserverReturn = UseWebObserverReturn ```tsx -export type UseWebObserverReturn = Pausable & { +export type UseWebObserverReturns = Pausable & { /** * ref that holds the observer instance */ @@ -88,5 +86,5 @@ export type UseWebObserverReturn = Pausable & { isSupported: boolean } -export type UseMutationObserverReturn = UseWebObserverReturn +export type UseMutationObserverReturns = UseWebObserverReturns ``` diff --git a/src/use-mutation-observer/index.ts b/src/use-mutation-observer/index.ts index d582b3ec..5a9e90e1 100644 --- a/src/use-mutation-observer/index.ts +++ b/src/use-mutation-observer/index.ts @@ -1,17 +1,17 @@ import { useWebObserver } from '../use-web-observer' import type { ElementTarget } from '../use-target-element' -import type { UseWebObserverOptions, UseWebObserverReturn } from '../use-web-observer' +import type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer' import type { Arrayable } from '../utils/basic' export interface UseMutationObserverOptions extends UseWebObserverOptions, MutationObserverInit {} -export interface UseMutationObserverReturn extends UseWebObserverReturn {} +export interface UseMutationObserverReturns extends UseWebObserverReturns {} export function useMutationObserver( target: Arrayable, callback: MutationCallback = () => {}, options: UseMutationObserverOptions = {}, -): UseMutationObserverReturn { +): UseMutationObserverReturns { const { immediate = true, ...observerOptions } = options return useWebObserver('MutationObserver', target, callback, { immediate }, undefined, observerOptions) diff --git a/src/use-network/index.mdx b/src/use-network/index.mdx index fd618f4d..505540bf 100644 --- a/src/use-network/index.mdx +++ b/src/use-network/index.mdx @@ -34,7 +34,7 @@ const network = useNetwork() ### Returns ```tsx -export type UseNetworkReturn = { +export type UseNetworkReturns = { /** * A Ref Getter to check if the browser supports the Network Information API. */ diff --git a/src/use-network/index.ts b/src/use-network/index.ts index a77a4db6..1150bdba 100644 --- a/src/use-network/index.ts +++ b/src/use-network/index.ts @@ -8,7 +8,7 @@ import { now } from '../utils/basic' export type NetworkType = 'bluetooth' | 'cellular' | 'ethernet' | 'none' | 'wifi' | 'wimax' | 'other' | 'unknown' export type NetworkEffectiveType = 'slow-2g' | '2g' | '3g' | '4g' | undefined -export interface UseNetworkReturn { +export interface UseNetworkReturns { /** * A Ref Getter to check if the browser supports the Network Information API. */ @@ -53,7 +53,7 @@ export interface UseNetworkReturn { type: NetworkType } -export interface ExtendedNavigator extends Navigator { +interface ExtendedNavigator extends Navigator { connection?: { downlink: number downlinkMax: number @@ -67,7 +67,7 @@ export interface ExtendedNavigator extends Navigator { } } -export function useNetwork(): UseNetworkReturn { +export function useNetwork(): UseNetworkReturns { const isSupported = useSupported(() => 'connection' in navigator) const connectionRef = useRef(null) @@ -99,7 +99,7 @@ export function useNetwork(): UseNetworkReturn { return { isSupported, ...state } } -function getNetwork(): Omit { +function getNetwork(): Omit { return { isOnline: navigator.onLine, offlineAt: navigator.onLine ? undefined : now(), diff --git a/src/use-now/index.mdx b/src/use-now/index.mdx index 14e45f85..820631a5 100644 --- a/src/use-now/index.mdx +++ b/src/use-now/index.mdx @@ -64,5 +64,5 @@ import { Tip } from '@/components' If `controls` is `true`, returns an object with `now` and `Pausable` Instance, else returns the current `Date` instance. ```tsx -export type UseNowReturn = Controls extends true ? { now: Date } & Pausable : Date +export type UseNowReturns = Controls extends true ? { now: Date } & Pausable : Date ``` diff --git a/src/use-now/index.ts b/src/use-now/index.ts index 68506a72..e99a3bb1 100644 --- a/src/use-now/index.ts +++ b/src/use-now/index.ts @@ -24,11 +24,11 @@ export interface UseNowOptions extends UseIntervalFnOp callback?: (now: Date) => void } -export type UseNowReturn = Controls extends true ? { now: Date } & Pausable : Date +export type UseNowReturns = Controls extends true ? { now: Date } & Pausable : Date -export function useNow(options?: UseNowOptions): UseNowReturn -export function useNow(options: UseNowOptions): UseNowReturn -export function useNow(options: UseNowOptions = {}): UseNowReturn { +export function useNow(options?: UseNowOptions): UseNowReturns +export function useNow(options: UseNowOptions): UseNowReturns +export function useNow(options: UseNowOptions = {}): UseNowReturns { const { controls: exposeControls = false, callback, diff --git a/src/use-parallax/index.mdx b/src/use-parallax/index.mdx index f28fdd33..c16b8f67 100644 --- a/src/use-parallax/index.mdx +++ b/src/use-parallax/index.mdx @@ -65,7 +65,7 @@ export type UseParallaxOptions = { ```tsx -export interface UseParallaxReturn extends Pausable { +export interface UseParallaxReturns extends Pausable { /** * Roll value. Scaled to `-0.5 ~ 0.5` */ diff --git a/src/use-parallax/index.ts b/src/use-parallax/index.ts index a6657bad..2018d33e 100644 --- a/src/use-parallax/index.ts +++ b/src/use-parallax/index.ts @@ -25,7 +25,7 @@ export interface UseParallaxOptions { mouseRollAdjust?: (i: number) => number } -export interface UseParallaxReturn extends Pausable { +export interface UseParallaxReturns extends Pausable { /** * Roll value. Scaled to `-0.5 ~ 0.5` */ @@ -44,7 +44,7 @@ export interface UseParallaxReturn extends Pausable { elementStyle: (rotateRatio?: number, duration?: number) => React.CSSProperties } -export function useParallax(target: ElementTarget, options: UseParallaxOptions = {}): UseParallaxReturn { +export function useParallax(target: ElementTarget, options: UseParallaxOptions = {}): UseParallaxReturns { const latest = useLatest({ deviceOrientationTiltAdjust: (e) => e, deviceOrientationRollAdjust: (e) => e, diff --git a/src/use-parent-element/index.mdx b/src/use-parent-element/index.mdx index feb041c9..e9bcd9fd 100644 --- a/src/use-parent-element/index.mdx +++ b/src/use-parent-element/index.mdx @@ -42,5 +42,5 @@ import { Tip } from '@/components' An `HTMLElement` or `null`. ```tsx -export type UseParentElementReturn = HTMLElement | null +export type UseParentElementReturns = HTMLElement | null ``` diff --git a/src/use-parent-element/index.ts b/src/use-parent-element/index.ts index 88eccff2..97b39d26 100644 --- a/src/use-parent-element/index.ts +++ b/src/use-parent-element/index.ts @@ -4,11 +4,11 @@ import { normalizeElement, useTargetElement } from '../use-target-element' import type { ElementTarget } from '../use-target-element' -export type UseParentElementReturn = HTMLElement | null +export type UseParentElementReturns = HTMLElement | null export function useParentElement( target: ElementTarget, -): UseParentElementReturn { +): UseParentElementReturns { const el = useTargetElement(target) const [parent, setParent] = useSafeState(null) diff --git a/src/use-performance-observer/index.mdx b/src/use-performance-observer/index.mdx index 3b81fbc0..06ac24a0 100644 --- a/src/use-performance-observer/index.mdx +++ b/src/use-performance-observer/index.mdx @@ -65,7 +65,7 @@ import { Tip } from '@/components' ```tsx -export type UseWebObserverReturn = Pausable & { +export type UseWebObserverReturns = Pausable & { /** * ref that holds the observer instance */ @@ -76,5 +76,5 @@ export type UseWebObserverReturn = Pausable & { isSupported: boolean } -export type UsePerformanceObserverReturn = UseWebObserverReturn +export type UsePerformanceObserverReturns = UseWebObserverReturns ``` diff --git a/src/use-performance-observer/index.ts b/src/use-performance-observer/index.ts index 2aef0db0..559f7964 100644 --- a/src/use-performance-observer/index.ts +++ b/src/use-performance-observer/index.ts @@ -1,14 +1,14 @@ import { useWebObserver } from '../use-web-observer' -import type { UseWebObserverOptions, UseWebObserverReturn } from '../use-web-observer' +import type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer' export interface UsePerformanceObserverOptions extends UseWebObserverOptions, PerformanceObserverInit {} -export interface UsePerformanceObserverReturn extends UseWebObserverReturn {} +export interface UsePerformanceObserverReturns extends UseWebObserverReturns {} export function usePerformanceObserver( callback: PerformanceObserverCallback = () => {}, options: UsePerformanceObserverOptions = {}, -): UsePerformanceObserverReturn { +): UsePerformanceObserverReturns { const { immediate = true, ...observerOptions } = options return useWebObserver('PerformanceObserver', undefined, callback, { immediate }, undefined, observerOptions) diff --git a/src/use-permission/index.mdx b/src/use-permission/index.mdx index 356d7d9d..422e6ce3 100644 --- a/src/use-permission/index.mdx +++ b/src/use-permission/index.mdx @@ -83,7 +83,7 @@ export type UsePermissionOptions = { ### Returns ```tsx -export type UsePermissionReturn = Controls extends true +export type UsePermissionReturns = Controls extends true ? { /** * A Ref Getter to check if the permission is supported diff --git a/src/use-permission/index.ts b/src/use-permission/index.ts index f9594e44..d9e0f5c9 100644 --- a/src/use-permission/index.ts +++ b/src/use-permission/index.ts @@ -47,7 +47,7 @@ export interface UsePermissionOptions { onStateChange?: (state: PermissionState) => void } -export type UsePermissionReturn = Controls extends true +export type UsePermissionReturns = Controls extends true ? { /** * A Ref Getter to check if the permission is supported @@ -67,15 +67,15 @@ export type UsePermissionReturn = Controls extends tru export function usePermission( permissionDesc: PermissionDesc, options?: UsePermissionOptions, -): UsePermissionReturn +): UsePermissionReturns export function usePermission( permissionDesc: PermissionDesc, options: UsePermissionOptions, -): UsePermissionReturn +): UsePermissionReturns export function usePermission( permissionDesc: PermissionDesc, options: UsePermissionOptions = {}, -): UsePermissionReturn { +): UsePermissionReturns { const { controls: exposeControls = false, immediate = true, onStateChange } = options const desc = permissionDesc diff --git a/src/use-reporting-observer/index.mdx b/src/use-reporting-observer/index.mdx index 6be6f9f6..b26e8bc6 100644 --- a/src/use-reporting-observer/index.mdx +++ b/src/use-reporting-observer/index.mdx @@ -62,7 +62,7 @@ import { Tip } from '@/components' ```tsx -export type UseWebObserverReturn = Pausable & { +export type UseWebObserverReturns = Pausable & { /** * ref that holds the observer instance */ @@ -73,5 +73,5 @@ export type UseWebObserverReturn = Pausable & { isSupported: boolean } -export interface UseReportingObserverReturn extends UseWebObserverReturn {} +export interface UseReportingObserverReturns extends UseWebObserverReturns {} ``` diff --git a/src/use-reporting-observer/index.ts b/src/use-reporting-observer/index.ts index b5439061..312e8ba7 100644 --- a/src/use-reporting-observer/index.ts +++ b/src/use-reporting-observer/index.ts @@ -1,14 +1,14 @@ import { useWebObserver } from '../use-web-observer' -import type { UseWebObserverOptions, UseWebObserverReturn } from '../use-web-observer' +import type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer' export interface UseReportingObserverOptions extends UseWebObserverOptions, ReportingObserverOptions {} -export interface UseReportingObserverReturn extends UseWebObserverReturn {} +export interface UseReportingObserverReturns extends UseWebObserverReturns {} export function useReportingObserver( callback: ReportingObserverCallback, options: UseReportingObserverOptions = {}, -): UseReportingObserverReturn { +): UseReportingObserverReturns { const { immediate = true, ...initOptions } = options return useWebObserver('ReportingObserver', undefined, callback, { immediate }, initOptions) } diff --git a/src/use-resize-observer/index.mdx b/src/use-resize-observer/index.mdx index acfbf229..55e3fd5d 100644 --- a/src/use-resize-observer/index.mdx +++ b/src/use-resize-observer/index.mdx @@ -64,7 +64,7 @@ import { Tip } from '@/components' ```tsx -export type UseWebObserverReturn = Pausable & { +export type UseWebObserverReturns = Pausable & { /** * ref that holds the observer instance */ @@ -75,5 +75,5 @@ export type UseWebObserverReturn = Pausable & { isSupported: boolean } -export interface UseResizeObserverReturn extends Pausable, UseWebObserverReturn {} +export interface UseResizeObserverReturns extends Pausable, UseWebObserverReturns {} ``` diff --git a/src/use-resize-observer/index.ts b/src/use-resize-observer/index.ts index be955fee..1f933159 100644 --- a/src/use-resize-observer/index.ts +++ b/src/use-resize-observer/index.ts @@ -2,7 +2,7 @@ import { useWebObserver } from '../use-web-observer' import type { Pausable } from '../use-pausable' import type { ElementTarget } from '../use-target-element' -import type { UseWebObserverOptions, UseWebObserverReturn } from '../use-web-observer' +import type { UseWebObserverOptions, UseWebObserverReturns } from '../use-web-observer' import type { Arrayable } from '../utils/basic' export interface UseResizeObserverOptions extends UseWebObserverOptions, ResizeObserverOptions { @@ -10,13 +10,13 @@ export interface UseResizeObserverOptions extends UseWebObserverOptions, ResizeO box?: ResizeObserverBoxOptions } -export interface UseResizeObserverReturn extends Pausable, UseWebObserverReturn {} +export interface UseResizeObserverReturns extends Pausable, UseWebObserverReturns {} export function useResizeObserver( target: Arrayable>, callback: ResizeObserverCallback, options: UseResizeObserverOptions = {}, -): UseResizeObserverReturn { +): UseResizeObserverReturns { const { immediate = true, ...observerOptions } = options return useWebObserver('ResizeObserver', target, callback, { immediate }, undefined, observerOptions) } diff --git a/src/use-script-tag/index.mdx b/src/use-script-tag/index.mdx index 9a2ffa1a..5436ec4f 100644 --- a/src/use-script-tag/index.mdx +++ b/src/use-script-tag/index.mdx @@ -113,7 +113,7 @@ export interface UseScriptTagOptions { ### Returns ```tsx -export type UseScriptTagReturn = { +export type UseScriptTagReturns = { /** * The script element Ref */ diff --git a/src/use-script-tag/index.ts b/src/use-script-tag/index.ts index 58327c46..3b1a00ec 100644 --- a/src/use-script-tag/index.ts +++ b/src/use-script-tag/index.ts @@ -74,7 +74,7 @@ export interface UseScriptTagOptions { attrs?: Record } -export type UseScriptTagReturn = { +export type UseScriptTagReturns = { /** * The script element Ref */ @@ -95,7 +95,7 @@ export function useScriptTag( src: string, onLoaded: (el: HTMLScriptElement) => void = noop, options: UseScriptTagOptions = {}, -): UseScriptTagReturn { +): UseScriptTagReturns { const { immediate = true, manual = false, diff --git a/src/use-scroll-lock/index.mdx b/src/use-scroll-lock/index.mdx index 49213647..fc3b0116 100644 --- a/src/use-scroll-lock/index.mdx +++ b/src/use-scroll-lock/index.mdx @@ -44,7 +44,7 @@ A `boolean` value to determine the initial state of the scroll lock. ### Returns ```tsx -export type UseScrollLockReturn = [ +export type UseScrollLockReturns = [ /** * Whether the scroll is locked */ diff --git a/src/use-scroll-lock/index.ts b/src/use-scroll-lock/index.ts index d0748b1d..1fca779a 100644 --- a/src/use-scroll-lock/index.ts +++ b/src/use-scroll-lock/index.ts @@ -9,7 +9,7 @@ import { useUnmount } from '../use-unmount' import type { ReactSetState } from '../use-safe-state' import type { ElementTarget } from '../use-target-element' -export type UseScrollLockReturn = [ +export type UseScrollLockReturns = [ /** * Whether the scroll is locked */ @@ -39,7 +39,7 @@ const globalOverflowCache = new WeakMap( target: ElementTarget, initialState = false, -): UseScrollLockReturn { +): UseScrollLockReturns { const el = useTargetElement(target) const [isLocked, setLocked] = useSafeState(initialState) diff --git a/src/use-scroll/index.mdx b/src/use-scroll/index.mdx index f42a1141..3e1ca7c1 100644 --- a/src/use-scroll/index.mdx +++ b/src/use-scroll/index.mdx @@ -81,7 +81,7 @@ export interface UseScrollOptions { ```tsx -export interface UseScrollReturn extends Pausable { +export interface UseScrollReturns extends Pausable { /** * scroll x position */ diff --git a/src/use-scroll/index.ts b/src/use-scroll/index.ts index d0b92fbd..c056e462 100644 --- a/src/use-scroll/index.ts +++ b/src/use-scroll/index.ts @@ -57,7 +57,7 @@ export interface UseScrollOptions { immediate?: boolean } -export interface UseScrollReturn extends Pausable { +export interface UseScrollReturns extends Pausable { /** * scroll x position */ @@ -102,7 +102,7 @@ const ARRIVED_STATE_THRESHOLD_PIXELS = 1 export function useScroll( target: ElementTarget, options: UseScrollOptions = {}, -): UseScrollReturn { +): UseScrollReturns { const { throttle = 0, idle = 200, diff --git a/src/use-signal-state/index.mdx b/src/use-signal-state/index.mdx index 7b1ce25e..c24ebfa8 100644 --- a/src/use-signal-state/index.mdx +++ b/src/use-signal-state/index.mdx @@ -44,5 +44,5 @@ See [useSafeState#options](/reference/use-safe-state/#options) for more details. ### Returns ```tsx -export type UseSignalStateReturn = [() => T, ReactSetState] +export type UseSignalStateReturns = [() => T, ReactSetState] ``` diff --git a/src/use-signal-state/index.ts b/src/use-signal-state/index.ts index 107da49b..29d38318 100644 --- a/src/use-signal-state/index.ts +++ b/src/use-signal-state/index.ts @@ -7,9 +7,9 @@ import type { Gettable } from '../utils/basic' export interface UseSignalStateOptions extends UseSafeStateOptions {} -export type UseSignalStateReturn = [() => T, ReactSetState] +export type UseSignalStateReturns = [() => T, ReactSetState] -export function useSignalState(state: Gettable, options: UseSignalStateOptions = {}): UseSignalStateReturn { +export function useSignalState(state: Gettable, options: UseSignalStateOptions = {}): UseSignalStateReturns { const [_state, setState] = useSafeState(state, options) const stateRef = useLatest(_state) const stateGetter = useStableFn(() => stateRef.current) diff --git a/src/use-spring-value/index.mdx b/src/use-spring-value/index.mdx index edfc5aac..10b2d164 100644 --- a/src/use-spring-value/index.mdx +++ b/src/use-spring-value/index.mdx @@ -77,7 +77,7 @@ export type Pausable void } -export type UseSpringValueReturn = Pausable & { +export type UseSpringValueReturns = Pausable & { /** * The current value of the spring. */ diff --git a/src/use-spring-value/index.ts b/src/use-spring-value/index.ts index 97832776..0f9d1b63 100644 --- a/src/use-spring-value/index.ts +++ b/src/use-spring-value/index.ts @@ -30,7 +30,7 @@ export interface UseSpringValueConfig { precision?: number } -export interface UseSpringValueReturn extends Pausable { +export interface UseSpringValueReturns extends Pausable { /** * The current value of the spring. */ @@ -41,7 +41,7 @@ export interface UseSpringValueReturn extends Pausable { restart(): void } -export function useSpringValue(start: number, end: number, config: UseSpringValueConfig = {}): UseSpringValueReturn { +export function useSpringValue(start: number, end: number, config: UseSpringValueConfig = {}): UseSpringValueReturns { const { stiffness = 220, damping = 50, mass = 1, precision = 0.01, immediate = true } = config const [value, setValue] = useSafeState(start) diff --git a/src/use-state-history/index.ts b/src/use-state-history/index.ts index 3a1afd92..3c24bdd9 100644 --- a/src/use-state-history/index.ts +++ b/src/use-state-history/index.ts @@ -4,21 +4,21 @@ import { usePausableUpdateDeepCompareEffect } from '../use-pausable-update-deep- import { usePausableUpdateEffect } from '../use-pausable-update-effect' import { useStableFn } from '../use-stable-fn' -import type { UseManualStateHistoryOptions, UseManualStateHistoryReturn } from '../use-manual-state-history' +import type { UseManualStateHistoryOptions, UseManualStateHistoryReturns } from '../use-manual-state-history' import type { Pausable } from '../use-pausable' export interface UseStateHistoryOptions extends UseManualStateHistoryOptions { deep?: boolean } -export interface UseStateHistoryReturn - extends UseManualStateHistoryReturn, +export interface UseStateHistoryReturns + extends UseManualStateHistoryReturns, Pausable<[commit?: boolean], [commit?: boolean]> {} export function useStateHistory( source: Raw, options: UseStateHistoryOptions = {}, -): UseStateHistoryReturn { +): UseStateHistoryReturns { const isDeep = options.deep || false const manualHistory = useManualStateHistory(source, { ...options, clone: options.clone || isDeep }) diff --git a/src/use-stepper/index.mdx b/src/use-stepper/index.mdx index 7acf2472..64f109fa 100644 --- a/src/use-stepper/index.mdx +++ b/src/use-stepper/index.mdx @@ -42,7 +42,7 @@ A `number` that represents the initial step index. ### Returns ```tsx -export interface UseStepperReturn { +export interface UseStepperReturns { /** * List of steps. */ diff --git a/src/use-stepper/index.ts b/src/use-stepper/index.ts index e3dafe54..3143f237 100644 --- a/src/use-stepper/index.ts +++ b/src/use-stepper/index.ts @@ -2,7 +2,7 @@ import { useCounter } from '../use-counter' import { useLatest } from '../use-latest' import { useStableFn } from '../use-stable-fn' -export interface UseStepperReturn { +export interface UseStepperReturns { /** * List of steps. */ @@ -77,7 +77,7 @@ export interface UseStepperReturn { isAfter: (step: StepName) => boolean } -export function useStepper(steps: T[], initialIdx?: number): UseStepperReturn { +export function useStepper(steps: T[], initialIdx?: number): UseStepperReturns { const [idx, actions] = useCounter(initialIdx ?? 0) const at = useStableFn((index: number) => { diff --git a/src/use-style-tag/index.mdx b/src/use-style-tag/index.mdx index 35de3083..c80bf93b 100644 --- a/src/use-style-tag/index.mdx +++ b/src/use-style-tag/index.mdx @@ -65,7 +65,7 @@ export interface UseStyleTagOptions { ### Returns ```tsx -export interface UseStyleTagReturn { +export interface UseStyleTagReturns { /** * Unique identifier of the style tag */ diff --git a/src/use-style-tag/index.ts b/src/use-style-tag/index.ts index 2f194622..a4dd702c 100644 --- a/src/use-style-tag/index.ts +++ b/src/use-style-tag/index.ts @@ -9,7 +9,7 @@ import { isClient } from '../utils/basic' import type { MutableRefObject } from 'react' -export interface UseStyleTagReturn { +export interface UseStyleTagReturns { /** * Unique identifier of the style tag */ @@ -71,7 +71,7 @@ export interface UseStyleTagOptions { const globalState = /* #__PURE__ */ { id: 0 } -export function useStyleTag(initialCss = '', options: UseStyleTagOptions = {}): UseStyleTagReturn { +export function useStyleTag(initialCss = '', options: UseStyleTagOptions = {}): UseStyleTagReturns { const isLoaded = useRef(false) const styleTag = useRef(null) diff --git a/src/use-supported/index.mdx b/src/use-supported/index.mdx index 86573b07..ba2e2fae 100644 --- a/src/use-supported/index.mdx +++ b/src/use-supported/index.mdx @@ -41,6 +41,4 @@ An array of dependencies to re-run the check when the value changes. ### Returns -```tsx -export type UseIsSupportedReturn = boolean -``` +A `boolean` value that indicates if the feature is supported. diff --git a/src/use-text-direction/index.mdx b/src/use-text-direction/index.mdx index 7397afc3..60ff2f46 100644 --- a/src/use-text-direction/index.mdx +++ b/src/use-text-direction/index.mdx @@ -53,7 +53,7 @@ export interface UseTextDirectionOptions { ### Returns ```tsx -export type UseTextDirectionReturn = [ +export type UseTextDirectionReturns = [ /** * The current text direction value. */ diff --git a/src/use-text-direction/index.ts b/src/use-text-direction/index.ts index 19fb7ab6..7e92b160 100644 --- a/src/use-text-direction/index.ts +++ b/src/use-text-direction/index.ts @@ -23,7 +23,7 @@ export interface UseTextDirectionOptions { initialValue?: UseTextDirectionValue } -export type UseTextDirectionReturn = [ +export type UseTextDirectionReturns = readonly [ /** * The current text direction value. */ @@ -34,7 +34,7 @@ export type UseTextDirectionReturn = [ setDir: ReactSetState, ] -export function useTextDirection(options: UseTextDirectionOptions = {}): UseTextDirectionReturn { +export function useTextDirection(options: UseTextDirectionOptions = {}): UseTextDirectionReturns { const { target = 'html', initialValue = 'ltr' } = options const el = useTargetElement(target) diff --git a/src/use-text-selection/index.mdx b/src/use-text-selection/index.mdx index 0eb834f9..b9c7e849 100644 --- a/src/use-text-selection/index.mdx +++ b/src/use-text-selection/index.mdx @@ -34,7 +34,7 @@ const { text, rects, ranges, selectionRef } = useTextSelection() ### Returns ```tsx -export interface UseTextSelectionReturn { +export interface UseTextSelectionReturns { /** * A React Ref object that holds the current Selection object. */ diff --git a/src/use-text-selection/index.ts b/src/use-text-selection/index.ts index 3cdfb29b..8822670b 100644 --- a/src/use-text-selection/index.ts +++ b/src/use-text-selection/index.ts @@ -4,7 +4,7 @@ import { useSafeState } from '../use-safe-state' import type { MutableRefObject } from 'react' -export interface UseTextSelectionReturn { +export interface UseTextSelectionReturns { /** * A React Ref object that holds the current Selection object. */ @@ -23,7 +23,7 @@ export interface UseTextSelectionReturn { ranges: Range[] } -export function useTextSelection(): UseTextSelectionReturn { +export function useTextSelection(): UseTextSelectionReturns { const selectionRef = useRef(null) const [selectionState, setSelectionState] = useSafeState({ text: '', diff --git a/src/use-time-ago/index.mdx b/src/use-time-ago/index.mdx index 04ad6d78..745fef27 100644 --- a/src/use-time-ago/index.mdx +++ b/src/use-time-ago/index.mdx @@ -99,7 +99,7 @@ import { Tip } from '@/components' ```tsx -export type UseTimeAgoReturn = Controls extends true +export type UseTimeAgoReturns = Controls extends true ? { timeAgo: string } & Pausable : string ``` diff --git a/src/use-time-ago/index.ts b/src/use-time-ago/index.ts index 4667cee0..687e0bfb 100644 --- a/src/use-time-ago/index.ts +++ b/src/use-time-ago/index.ts @@ -12,7 +12,7 @@ import type { DateLike } from '../use-date-format' import type { Pausable } from '../use-pausable' import type { Gettable } from '../utils/basic' -export type UseTimeAgoReturn = Controls extends true +export type UseTimeAgoReturns = Controls extends true ? { timeAgo: string } & Pausable : string @@ -35,11 +35,11 @@ export interface UseTimeAgoOptions( time: Gettable, options?: UseTimeAgoOptions, -): UseTimeAgoReturn +): UseTimeAgoReturns export function useTimeAgo( time: Gettable, options: UseTimeAgoOptions, -): UseTimeAgoReturn +): UseTimeAgoReturns export function useTimeAgo( time: Gettable, options: UseTimeAgoOptions = {}, diff --git a/src/use-timeout/index.mdx b/src/use-timeout/index.mdx index 14bc4909..1d4802b0 100644 --- a/src/use-timeout/index.mdx +++ b/src/use-timeout/index.mdx @@ -59,7 +59,7 @@ export interface UseTimeoutOptions = Controls extends true +export type UseTimeoutReturns = Controls extends true ? Pausable<[], Parameters | []> & { /** * Timeout state diff --git a/src/use-timeout/index.ts b/src/use-timeout/index.ts index 8e8b1737..d3a44789 100644 --- a/src/use-timeout/index.ts +++ b/src/use-timeout/index.ts @@ -21,7 +21,7 @@ export interface UseTimeoutOptions = Controls extends true +export type UseTimeoutReturns = Controls extends true ? Pausable<[], Parameters | []> & { /** * Timeout state @@ -34,11 +34,11 @@ export type UseTimeoutReturn): UseTimeoutReturn +export function useTimeout(interval?: number, options?: UseTimeoutOptions): UseTimeoutReturns export function useTimeout( interval: number, options: UseTimeoutOptions, -): UseTimeoutReturn +): UseTimeoutReturns export function useTimeout(interval = 1000, options: UseTimeoutOptions = {}) { const { controls: exposeControls = false, immediate, callback } = options const [isTimeout, setIsTimeout] = useSafeState(false) diff --git a/src/use-toggle/index.ts b/src/use-toggle/index.ts index 52b77229..7b521a16 100644 --- a/src/use-toggle/index.ts +++ b/src/use-toggle/index.ts @@ -12,13 +12,13 @@ export interface UseToggleReturnActions { setState: ReactSetState } -export type UseToggleReturn = [O | T, () => void, UseToggleReturnActions] +export type UseToggleReturns = [O | T, () => void, UseToggleReturnActions] -export function useToggle(one: true, theOther?: false): UseToggleReturn -export function useToggle(one: false, theOther?: true): UseToggleReturn -export function useToggle(one: boolean, theOther?: boolean): UseToggleReturn -export function useToggle(one: O, theOther: T): UseToggleReturn -export function useToggle(one: O, theOther: T): UseToggleReturn { +export function useToggle(one: true, theOther?: false): UseToggleReturns +export function useToggle(one: false, theOther?: true): UseToggleReturns +export function useToggle(one: boolean, theOther?: boolean): UseToggleReturns +export function useToggle(one: O, theOther: T): UseToggleReturns +export function useToggle(one: O, theOther: T): UseToggleReturns { const [state, setState] = useSafeState(one) const latest = useLatest({ one, theOther: isDefined(theOther) ? theOther : (!one as T) }) diff --git a/src/use-unmounted/index.ts b/src/use-unmounted/index.ts index b8b3c507..6bd67729 100644 --- a/src/use-unmounted/index.ts +++ b/src/use-unmounted/index.ts @@ -2,12 +2,10 @@ import { useRef } from 'react' import { useEffectOnce } from '../use-effect-once' import { useStableFn } from '../use-stable-fn' -export type UseUnmountedReturn = () => boolean - /** * Returns a function that returns whether the component is unmounted. */ -export function useUnmounted(): UseUnmountedReturn { +export function useUnmounted(): () => boolean { const unmountedRef = useRef(false) useEffectOnce(() => { diff --git a/src/use-url-search-params/index.mdx b/src/use-url-search-params/index.mdx index 3d9db91d..15744e91 100644 --- a/src/use-url-search-params/index.mdx +++ b/src/use-url-search-params/index.mdx @@ -77,5 +77,5 @@ export interface UseUrlSearchParamsOptions { ### Returns ```tsx -export type UseUrlSearchParamsReturn> = [T, UseSetStateSetMergedState, Noop] +export type UseUrlSearchParamsReturns> = [T, UseSetStateSetMergedState, Noop] ``` diff --git a/src/use-url-search-params/index.ts b/src/use-url-search-params/index.ts index 2b57a91f..932102b3 100644 --- a/src/use-url-search-params/index.ts +++ b/src/use-url-search-params/index.ts @@ -39,7 +39,7 @@ export interface UseUrlSearchParamsOptions { write?: boolean } -export type UseUrlSearchParamsReturn>> = [ +export type UseUrlSearchParamsReturns>> = [ T, UseSetStateSetMergedState, Noop, @@ -47,7 +47,7 @@ export type UseUrlSearchParamsReturn> = UrlParams, ->(mode: UseUrlSearchParamsMode = 'history', options: UseUrlSearchParamsOptions = {}): UseUrlSearchParamsReturn { +>(mode: UseUrlSearchParamsMode = 'history', options: UseUrlSearchParamsOptions = {}): UseUrlSearchParamsReturns { const { initialValue = {} as T, removeNullishValues: rmNullish = true, diff --git a/src/use-user-idle/index.mdx b/src/use-user-idle/index.mdx index 7518153c..38f69820 100644 --- a/src/use-user-idle/index.mdx +++ b/src/use-user-idle/index.mdx @@ -73,7 +73,7 @@ import { Tip } from '@/components' ```tsx -export interface UseUserIdleReturn extends Pausable<[reset?: boolean], [reset?: boolean]> { +export interface UseUserIdleReturns extends Pausable<[reset?: boolean], [reset?: boolean]> { /** * Whether the user is idle */ diff --git a/src/use-user-idle/index.ts b/src/use-user-idle/index.ts index e7b2834c..b919c120 100644 --- a/src/use-user-idle/index.ts +++ b/src/use-user-idle/index.ts @@ -39,7 +39,7 @@ export interface UseUserIdleOptions { immediate?: boolean } -export interface UseUserIdleReturn extends Pausable<[reset?: boolean], [reset?: boolean]> { +export interface UseUserIdleReturns extends Pausable<[reset?: boolean], [reset?: boolean]> { /** * Whether the user is idle */ @@ -59,7 +59,7 @@ export interface UseUserIdleReturn extends Pausable<[reset?: boolean], [reset?: const defaultEvents: WindowEventName[] = ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel'] const oneMinute = 60_000 -export function useUserIdle(timeout: number = oneMinute, options: UseUserIdleOptions = {}): UseUserIdleReturn { +export function useUserIdle(timeout: number = oneMinute, options: UseUserIdleOptions = {}): UseUserIdleReturns { const { immediate = true, initialState = false, watchVisibility = true, events = defaultEvents } = options const lastActiveRef = useRef(Date.now()) diff --git a/src/use-user-media/index.mdx b/src/use-user-media/index.mdx index c98f1383..fa690a21 100644 --- a/src/use-user-media/index.mdx +++ b/src/use-user-media/index.mdx @@ -62,7 +62,7 @@ export interface UseUserMediaOptions { ### Returns ```tsx -export interface UseUserMediaReturn extends Pausable { +export interface UseUserMediaReturns extends Pausable { /** * The current MediaStream */ diff --git a/src/use-user-media/index.ts b/src/use-user-media/index.ts index e789bc2b..fcbbb398 100644 --- a/src/use-user-media/index.ts +++ b/src/use-user-media/index.ts @@ -32,7 +32,7 @@ export interface UseUserMediaOptions { constraints?: MediaStreamConstraints } -export interface UseUserMediaReturn extends Pausable { +export interface UseUserMediaReturns extends Pausable { /** * The current MediaStream */ @@ -43,7 +43,7 @@ export interface UseUserMediaReturn extends Pausable { isSupported: boolean } -export function useUserMedia(options: UseUserMediaOptions = {}): UseUserMediaReturn { +export function useUserMedia(options: UseUserMediaOptions = {}): UseUserMediaReturns { const { autoSwitch = true, onStart, onStop, constraints = {} } = options const stream = useRef(null) diff --git a/src/use-web-observer/index.mdx b/src/use-web-observer/index.mdx index 2a96197e..328cb735 100644 --- a/src/use-web-observer/index.mdx +++ b/src/use-web-observer/index.mdx @@ -54,7 +54,7 @@ export interface UseWebObserverOptions { immediate?: boolean } -export interface UseWebObserverReturn extends Pausable { +export interface UseWebObserverReturns extends Pausable { /** * ref that holds the observer instance */ @@ -79,7 +79,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: IntersectionObserverInit, observerOptions?: undefined, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'MutationObserver', target: Arrayable, @@ -87,7 +87,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: MutationObserverInit, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'ResizeObserver', target: Arrayable, @@ -95,7 +95,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: ResizeObserverOptions, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'PerformanceObserver', target: undefined, @@ -103,7 +103,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: PerformanceObserverInit, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'ReportingObserver', target: undefined, @@ -111,5 +111,5 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: ReportingObserverOptions, observerOptions?: undefined, -): UseWebObserverReturn +): UseWebObserverReturns ``` diff --git a/src/use-web-observer/index.ts b/src/use-web-observer/index.ts index 2232d81c..7c09199f 100644 --- a/src/use-web-observer/index.ts +++ b/src/use-web-observer/index.ts @@ -19,7 +19,7 @@ export interface UseWebObserverOptions { immediate?: boolean } -export interface UseWebObserverReturn extends Pausable { +export interface UseWebObserverReturns extends Pausable { /** * ref that holds the observer instance */ @@ -48,7 +48,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: IntersectionObserverInit, observerOptions?: undefined, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'MutationObserver', target: Arrayable, @@ -56,7 +56,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: MutationObserverInit, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'ResizeObserver', target: Arrayable, @@ -64,7 +64,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: ResizeObserverOptions, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'PerformanceObserver', target: undefined, @@ -72,7 +72,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: undefined, observerOptions?: PerformanceObserverInit, -): UseWebObserverReturn +): UseWebObserverReturns export function useWebObserver( observer: 'ReportingObserver', target: undefined, @@ -80,7 +80,7 @@ export function useWebObserver( options?: UseWebObserverOptions, initOptions?: ReportingObserverOptions, observerOptions?: undefined, -): UseWebObserverReturn +): UseWebObserverReturns // biome-ignore lint/suspicious/noExplicitAny: for overload export function useWebObserver(...args: any[]): any { const [observer, target, callback, options = {}, initOptions = {}, observerOptions = {}] = args diff --git a/src/use-window-scroll/index.mdx b/src/use-window-scroll/index.mdx index dda41075..b7766921 100644 --- a/src/use-window-scroll/index.mdx +++ b/src/use-window-scroll/index.mdx @@ -47,7 +47,7 @@ export interface UseWindowScrollOptions { ### Returns ```tsx -export interface UseWindowScrollReturn extends Position { +export interface UseWindowScrollReturns extends Position { /** * Scrolls the window to the specified position. * diff --git a/src/use-window-scroll/index.ts b/src/use-window-scroll/index.ts index 7cec9a2d..4cde35a2 100644 --- a/src/use-window-scroll/index.ts +++ b/src/use-window-scroll/index.ts @@ -16,7 +16,7 @@ export interface UseWindowScrollOptions { behavior?: ScrollBehavior } -export interface UseWindowScrollReturn extends Position { +export interface UseWindowScrollReturns extends Position { /** * The maximum scroll position on the x-axis. */ @@ -49,7 +49,7 @@ export interface UseWindowScrollReturn extends Position { scrollToRight(): void } -export function useWindowScroll(options: UseWindowScrollOptions = {}): UseWindowScrollReturn { +export function useWindowScroll(options: UseWindowScrollOptions = {}): UseWindowScrollReturns { const { behavior = 'auto' } = options const [state, setState] = useSetState( diff --git a/src/use-window-size/index.mdx b/src/use-window-size/index.mdx index c668d1ca..df1dfae4 100644 --- a/src/use-window-size/index.mdx +++ b/src/use-window-size/index.mdx @@ -72,7 +72,7 @@ export interface WindowSize { height: number } -export interface UseWindowSizeReturn extends Size { +export interface UseWindowSizeReturns extends Size { /** * Update the window size. */ diff --git a/src/use-window-size/index.ts b/src/use-window-size/index.ts index d261abba..54937a23 100644 --- a/src/use-window-size/index.ts +++ b/src/use-window-size/index.ts @@ -34,14 +34,14 @@ export interface UseWindowSizeOptions { includeScrollbar?: boolean } -export interface UseWindowSizeReturn extends Size { +export interface UseWindowSizeReturns extends Size { /** * Update the window size. */ update(): void } -export function useWindowSize(options: UseWindowSizeOptions = {}): UseWindowSizeReturn { +export function useWindowSize(options: UseWindowSizeOptions = {}): UseWindowSizeReturns { const { initialWidth = Number.POSITIVE_INFINITY, initialHeight = Number.POSITIVE_INFINITY, diff --git a/src/utils/basic.ts b/src/utils/basic.ts index 6d76426b..19a5d791 100644 --- a/src/utils/basic.ts +++ b/src/utils/basic.ts @@ -110,7 +110,7 @@ export function ensureSSRSecurity(fn: () => T, fallback: S): T { return isClient ? fn() : fallback } -export interface PromiseWithResolversReturn { +export interface PromiseWithResolversReturns { resolve: (value: T | PromiseLike) => void reject: (reason: unknown) => void promise: Promise @@ -121,7 +121,7 @@ export interface PromiseWithResolversReturn { * * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/withResolvers#browser_compatibility */ -export function createPromiseWithResolvers(): PromiseWithResolversReturn { +export function createPromiseWithResolvers(): PromiseWithResolversReturns { let resolve!: (value: T | PromiseLike) => void let reject!: (reason: unknown) => void