UNPKG

@dolthub/react-hooks

Version:

A collection of React hooks for common tasks

88 lines (67 loc) 3.53 kB
import React, { DependencyList, useEffect, Dispatch, SetStateAction } from 'react'; import { KeyMap } from 'react-hotkeys'; export { GlobalHotKeys } from 'react-hotkeys'; declare function useAnchorTag(): void; declare function useBaseUrl(getUrlFn: () => string, defaultUrl?: string): string; declare function useContextWithError<T>(ctx: React.Context<T>): T; type Maybe<T> = T | null | undefined; type ReturnType$6 = Readonly<{ active: boolean; start: () => void; stop: () => void; }>; declare function useDelay(length?: number, errors?: ReadonlyArray<Maybe<string>>): ReturnType$6; type ReturnType$5 = { onDownload: (contents: string) => void; }; declare function createLink(href: string, fileName?: string): void; declare function useDownloadFile(fileName: string, fileType?: string): ReturnType$5; declare function useEffectAsync(fn: (s: { subscribed: boolean; }) => Promise<void>, deps?: DependencyList): void; declare function useEffectOnMount(fn: () => void): void; declare function useElementIsVisible(id: string, rerender?: boolean): boolean; type ReturnType$4 = { setScrollToTop: (t: boolean) => void; setRefocus: (r: boolean) => void; }; declare function useFocus(containerId?: string): ReturnType$4; type ReturnType$3 = { keyMap: KeyMap | undefined; handlers: { [key: string]: (keyEvent?: KeyboardEvent | undefined) => void; }; }; declare function useHotKeysForToggle(toggle: () => void): ReturnType$3; declare function useInterval(callback: () => void, delayMs: number | null): void; declare function useIsSignedIn(tokenKey: string): boolean; declare const useIsomorphicLayoutEffect: typeof useEffect; declare function useOnClickOutside(excludingRef: React.MutableRefObject<any>, action: () => void): void; declare function useReactiveHeight<E extends HTMLElement>(): E["clientHeight"]; declare function useReactiveElementHeight<E extends HTMLElement>(elem?: E | null): E["clientHeight"]; declare function useReactiveWidth<E extends HTMLElement>(mobileBreakpoint?: number): { clientWidth: E["clientWidth"]; isMobile: boolean; }; declare function useReactiveScrollWidth<E extends HTMLElement>(elem?: E | null): { scrollWidth: E["scrollWidth"]; windowInnerWidth: Window["innerWidth"]; }; type ReturnType$2 = { history: string[]; addQuery: (q: string) => void; addMutation: (q: string) => void; queryIsRecentMutation: (q: string) => boolean; getNextQuery: () => string | undefined; getPrevQuery: (shouldSkipFirst: (s: string) => boolean) => string | undefined; queryIdx: number | undefined; }; declare function useSessionQueryHistory(databaseName: string): ReturnType$2; type ReturnType$1 = { containerHeight: number; }; declare function useSetContainerHeight(componentID: string): ReturnType$1; declare function useSetState<S extends Record<string, unknown>>(initialState: S): [S, React.Dispatch<Partial<S>>]; type ReturnType = [string, Dispatch<SetStateAction<string>>]; declare function useStateWithSessionStorage(storageKey: string, defaultValue?: string): ReturnType; export { createLink, useAnchorTag, useBaseUrl, useContextWithError, useDelay, useDownloadFile, useEffectAsync, useEffectOnMount, useElementIsVisible, useFocus, useHotKeysForToggle, useInterval, useIsSignedIn, useIsomorphicLayoutEffect, useOnClickOutside, useReactiveElementHeight, useReactiveHeight, useReactiveScrollWidth, useReactiveWidth, useSessionQueryHistory, useSetContainerHeight, useSetState, useStateWithSessionStorage };