ahooks

  • Version 3.7.11
  • Published
  • 578 kB
  • 9 dependencies
  • MIT license

Install

npm i ahooks
yarn add ahooks
pnpm add ahooks

Overview

react hooks library

Index

Variables

variable useDeepCompareEffect

const useDeepCompareEffect: any;

    variable useDeepCompareLayoutEffect

    const useDeepCompareLayoutEffect: any;

      variable useIsomorphicLayoutEffect

      const useIsomorphicLayoutEffect: any;

        variable useUpdateEffect

        const useUpdateEffect: any;

          variable useUpdateLayoutEffect

          const useUpdateLayoutEffect: any;

            Functions

            function clearCache

            clearCache: (key?: string | string[]) => void;

              function configResponsive

              configResponsive: (config: ResponsiveConfig) => void;

                function createUpdateEffect

                createUpdateEffect: (hook: EffectHookType) => EffectHookType;

                  function useAntdTable

                  useAntdTable: <TData extends Data, TParams extends Params>(
                  service: Service<TData, TParams>,
                  options?: AntdTableOptions<TData, TParams>
                  ) => AntdTableResult<TData, TParams>;

                    function useAsyncEffect

                    useAsyncEffect: (
                    effect: () => AsyncGenerator<void, void, void> | Promise<void>,
                    deps?: DependencyList
                    ) => void;

                      function useBoolean

                      useBoolean: (defaultValue?: boolean) => [boolean, Actions];

                        function useClickAway

                        useClickAway: <T extends Event = Event>(
                        onClickAway: (event: T) => void,
                        target: BasicTarget | BasicTarget[],
                        eventName?: DocumentEventKey | DocumentEventKey[]
                        ) => void;

                          function useControllableValue

                          useControllableValue: {
                          <T = any>(props: StandardProps<T>): [T, (v: SetStateAction<T>) => void];
                          <T = any>(props?: Props, options?: Options<T>): [
                          T,
                          (v: SetStateAction<T>, ...args: any[]) => void
                          ];
                          };

                            function useCookieState

                            useCookieState: (
                            cookieKey: string,
                            options?: Options
                            ) => readonly [
                            string,
                            (
                            newValue: string | ((prevState: State) => State),
                            newOptions?: Cookies.CookieAttributes
                            ) => void
                            ];

                              function useCountDown

                              useCountDown: (options?: Options) => readonly [number, FormattedRes];

                                function useCounter

                                useCounter: (
                                initialValue?: number,
                                options?: Options
                                ) => readonly [
                                number,
                                {
                                readonly inc: (delta?: number) => void;
                                readonly dec: (delta?: number) => void;
                                readonly set: (value: ValueParam) => void;
                                readonly reset: () => void;
                                }
                                ];

                                  function useCreation

                                  useCreation: <T>(factory: () => T, deps: DependencyList) => T;

                                    function useDebounce

                                    useDebounce: <T>(value: T, options?: DebounceOptions) => T;

                                      function useDebounceEffect

                                      useDebounceEffect: (
                                      effect: EffectCallback,
                                      deps?: DependencyList,
                                      options?: DebounceOptions
                                      ) => void;

                                        function useDebounceFn

                                        useDebounceFn: <T extends noop>(
                                        fn: T,
                                        options?: DebounceOptions
                                        ) => { run: any; cancel: () => void; flush: () => ReturnType<T> | undefined };

                                          function useDocumentVisibility

                                          useDocumentVisibility: () => VisibilityState;

                                            function useDrag

                                            useDrag: <T>(data: T, target: BasicTarget, options?: Options) => void;

                                              function useDrop

                                              useDrop: (target: BasicTarget, options?: Options) => void;

                                                function useDynamicList

                                                useDynamicList: <T>(initialList?: T[]) => {
                                                list: T[];
                                                insert: (index: number, item: T) => void;
                                                merge: (index: number, items: T[]) => void;
                                                replace: (index: number, item: T) => void;
                                                remove: (index: number) => void;
                                                getKey: (index: number) => number;
                                                getIndex: (key: number) => number;
                                                move: (oldIndex: number, newIndex: number) => void;
                                                push: (item: T) => void;
                                                pop: () => void;
                                                unshift: (item: T) => void;
                                                shift: () => void;
                                                sortList: (result: T[]) => T[];
                                                resetList: (newList: T[]) => void;
                                                };

                                                  function useEventEmitter

                                                  useEventEmitter: <T = void>() => EventEmitter<T>;

                                                    function useEventListener

                                                    useEventListener: {
                                                    <K extends keyof HTMLElementEventMap>(
                                                    eventName: K,
                                                    handler: (ev: HTMLElementEventMap[K]) => void,
                                                    options?: Options<HTMLElement>
                                                    ): void;
                                                    <K extends keyof ElementEventMap>(
                                                    eventName: K,
                                                    handler: (ev: ElementEventMap[K]) => void,
                                                    options?: Options<Element>
                                                    ): void;
                                                    <K extends keyof DocumentEventMap>(
                                                    eventName: K,
                                                    handler: (ev: DocumentEventMap[K]) => void,
                                                    options?: Options<Document>
                                                    ): void;
                                                    <K extends keyof WindowEventMap>(
                                                    eventName: K,
                                                    handler: (ev: WindowEventMap[K]) => void,
                                                    options?: Options<Window>
                                                    ): void;
                                                    (eventName: string, handler: noop, options: Options<any>): void;
                                                    };

                                                      function useEventTarget

                                                      useEventTarget: <T, U = T>(
                                                      options?: Options<T, U>
                                                      ) => readonly [
                                                      T,
                                                      { readonly onChange: (e: EventTarget<U>) => void; readonly reset: () => void }
                                                      ];

                                                        function useExternal

                                                        useExternal: (path?: string, options?: Options) => Status;

                                                          function useFavicon

                                                          useFavicon: (href: string) => void;

                                                            function useFocusWithin

                                                            useFocusWithin: (target: BasicTarget, options?: Options) => boolean;

                                                              function useFullscreen

                                                              useFullscreen: (
                                                              target: BasicTarget,
                                                              options?: Options
                                                              ) => readonly [
                                                              boolean,
                                                              {
                                                              readonly enterFullscreen: () => void;
                                                              readonly exitFullscreen: () => void;
                                                              readonly toggleFullscreen: () => void;
                                                              readonly isEnabled: true;
                                                              }
                                                              ];

                                                                function useFusionTable

                                                                useFusionTable: <TData extends Data, TParams extends Params>(
                                                                service: Service<TData, TParams>,
                                                                options?: FusionTableOptions<TData, TParams>
                                                                ) => FusionTableResult<TData, TParams>;

                                                                  function useGetState

                                                                  useGetState: {
                                                                  <S>(initialState: S | (() => S)): [
                                                                  S,
                                                                  Dispatch<SetStateAction<S>>,
                                                                  GetStateAction<S>
                                                                  ];
                                                                  <S = undefined>(): [S, Dispatch<SetStateAction<S>>, GetStateAction<S>];
                                                                  };

                                                                    function useHistoryTravel

                                                                    useHistoryTravel: <T>(
                                                                    initialValue?: T,
                                                                    maxLength?: number
                                                                    ) => {
                                                                    value: T | undefined;
                                                                    backLength: number;
                                                                    forwardLength: number;
                                                                    setValue: (val: T) => void;
                                                                    go: (step: number) => void;
                                                                    back: () => void;
                                                                    forward: () => void;
                                                                    reset: (...params: any[]) => void;
                                                                    };

                                                                      function useHover

                                                                      useHover: (target: BasicTarget, options?: Options) => boolean;

                                                                        function useInfiniteScroll

                                                                        useInfiniteScroll: <TData extends Data>(
                                                                        service: Service<TData>,
                                                                        options?: InfiniteScrollOptions<TData>
                                                                        ) => {
                                                                        data: TData;
                                                                        loading: boolean;
                                                                        error: Error | undefined;
                                                                        loadingMore: boolean;
                                                                        noMore: boolean;
                                                                        loadMore: () => void;
                                                                        loadMoreAsync: () => Promise<TData>;
                                                                        reload: () => void;
                                                                        reloadAsync: () => Promise<TData>;
                                                                        mutate: any;
                                                                        cancel: () => void;
                                                                        };

                                                                          function useInterval

                                                                          useInterval: (
                                                                          fn: () => void,
                                                                          delay?: number,
                                                                          options?: { immediate?: boolean }
                                                                          ) => () => void;

                                                                            function useInViewport

                                                                            useInViewport: (
                                                                            target: BasicTarget | BasicTarget[],
                                                                            options?: Options
                                                                            ) => readonly [boolean | undefined, number | undefined];

                                                                              function useKeyPress

                                                                              useKeyPress: (
                                                                              keyFilter: KeyFilter,
                                                                              eventHandler: (event: KeyboardEvent, key: KeyType) => void,
                                                                              option?: Options
                                                                              ) => void;

                                                                                function useLatest

                                                                                useLatest: <T>(value: T) => any;

                                                                                  function useLocalStorageState

                                                                                  useLocalStorageState: <T>(
                                                                                  key: string,
                                                                                  options?: Options<T>
                                                                                  ) => readonly [T, (value?: SetState<T>) => void];

                                                                                    function useLockFn

                                                                                    useLockFn: <P extends any[] = any[], V = any>(
                                                                                    fn: (...args: P) => Promise<V>
                                                                                    ) => (...args: P) => Promise<V | undefined>;

                                                                                      function useLongPress

                                                                                      useLongPress: (
                                                                                      onLongPress: (event: EventType) => void,
                                                                                      target: BasicTarget,
                                                                                      { delay, moveThreshold, onClick, onLongPressEnd }?: Options
                                                                                      ) => void;

                                                                                        function useMap

                                                                                        useMap: <K, T>(
                                                                                        initialValue?: Iterable<readonly [K, T]>
                                                                                        ) => readonly [
                                                                                        Map<K, T>,
                                                                                        {
                                                                                        readonly set: (key: K, entry: T) => void;
                                                                                        readonly setAll: (newMap: Iterable<readonly [K, T]>) => void;
                                                                                        readonly remove: (key: K) => void;
                                                                                        readonly reset: () => void;
                                                                                        readonly get: (key: K) => T | undefined;
                                                                                        }
                                                                                        ];

                                                                                          function useMemoizedFn

                                                                                          useMemoizedFn: <T extends noop>(fn: T) => T;

                                                                                            function useMount

                                                                                            useMount: (fn: () => void) => void;

                                                                                              function useMouse

                                                                                              useMouse: (target?: BasicTarget) => CursorState;

                                                                                                function useMutationObserver

                                                                                                useMutationObserver: (
                                                                                                callback: MutationCallback,
                                                                                                target: BasicTarget,
                                                                                                options?: MutationObserverInit
                                                                                                ) => void;

                                                                                                  function useNetwork

                                                                                                  useNetwork: () => NetworkState;

                                                                                                    function usePagination

                                                                                                    usePagination: <TData extends Data, TParams extends Params>(
                                                                                                    service: Service<TData, TParams>,
                                                                                                    options?: PaginationOptions<TData, TParams>
                                                                                                    ) => PaginationResult<TData, TParams>;

                                                                                                      function usePrevious

                                                                                                      usePrevious: <T>(state: T, shouldUpdate?: ShouldUpdateFunc<T>) => T | undefined;

                                                                                                        function useRafInterval

                                                                                                        useRafInterval: (
                                                                                                        fn: () => void,
                                                                                                        delay: number | undefined,
                                                                                                        options?: { immediate?: boolean }
                                                                                                        ) => () => void;

                                                                                                          function useRafState

                                                                                                          useRafState: {
                                                                                                          <S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
                                                                                                          <S = undefined>(): [S, Dispatch<SetStateAction<S>>];
                                                                                                          };

                                                                                                            function useRafTimeout

                                                                                                            useRafTimeout: (fn: () => void, delay: number | undefined) => () => void;

                                                                                                              function useReactive

                                                                                                              useReactive: <S extends Record<string, any>>(initialState: S) => S;

                                                                                                                function useRequest

                                                                                                                useRequest: <TData, TParams extends any[]>(
                                                                                                                service: Service<TData, TParams>,
                                                                                                                options?: Options<TData, TParams>,
                                                                                                                plugins?: Plugin<TData, TParams>[]
                                                                                                                ) => import('./types').Result<TData, TParams>;

                                                                                                                  function useResetState

                                                                                                                  useResetState: <S>(
                                                                                                                  initialState: S | (() => S)
                                                                                                                  ) => [S, Dispatch<SetStateAction<S>>, ResetState];

                                                                                                                    function useResponsive

                                                                                                                    useResponsive: () => ResponsiveInfo;

                                                                                                                      function useSafeState

                                                                                                                      useSafeState: {
                                                                                                                      <S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>];
                                                                                                                      <S = undefined>(): [S, Dispatch<SetStateAction<S>>];
                                                                                                                      };

                                                                                                                        function useScroll

                                                                                                                        useScroll: (
                                                                                                                        target?: Target,
                                                                                                                        shouldUpdate?: ScrollListenController
                                                                                                                        ) => Position | undefined;

                                                                                                                          function useSelections

                                                                                                                          useSelections: <T>(
                                                                                                                          items: T[],
                                                                                                                          defaultSelected?: T[]
                                                                                                                          ) => {
                                                                                                                          readonly selected: T[];
                                                                                                                          readonly noneSelected: boolean;
                                                                                                                          readonly allSelected: boolean;
                                                                                                                          readonly partiallySelected: boolean;
                                                                                                                          readonly setSelected: any;
                                                                                                                          readonly isSelected: (item: T) => boolean;
                                                                                                                          readonly select: (item: T) => void;
                                                                                                                          readonly unSelect: (item: T) => void;
                                                                                                                          readonly toggle: (item: T) => void;
                                                                                                                          readonly selectAll: () => void;
                                                                                                                          readonly unSelectAll: () => void;
                                                                                                                          readonly toggleAll: () => void;
                                                                                                                          };

                                                                                                                            function useSessionStorageState

                                                                                                                            useSessionStorageState: <T>(
                                                                                                                            key: string,
                                                                                                                            options?: Options<T>
                                                                                                                            ) => readonly [T, (value?: SetState<T>) => void];

                                                                                                                              function useSet

                                                                                                                              useSet: <K>(
                                                                                                                              initialValue?: Iterable<K>
                                                                                                                              ) => readonly [
                                                                                                                              Set<K>,
                                                                                                                              {
                                                                                                                              readonly add: (key: K) => void;
                                                                                                                              readonly remove: (key: K) => void;
                                                                                                                              readonly reset: () => void;
                                                                                                                              }
                                                                                                                              ];

                                                                                                                                function useSetState

                                                                                                                                useSetState: <S extends Record<string, any>>(
                                                                                                                                initialState: S | (() => S)
                                                                                                                                ) => [S, SetState<S>];

                                                                                                                                  function useSize

                                                                                                                                  useSize: (target: BasicTarget) => Size | undefined;

                                                                                                                                    function useTextSelection

                                                                                                                                    useTextSelection: (target?: BasicTarget<Document | Element>) => State;

                                                                                                                                      function useThrottle

                                                                                                                                      useThrottle: <T>(value: T, options?: ThrottleOptions) => T;

                                                                                                                                        function useThrottleEffect

                                                                                                                                        useThrottleEffect: (
                                                                                                                                        effect: EffectCallback,
                                                                                                                                        deps?: DependencyList,
                                                                                                                                        options?: ThrottleOptions
                                                                                                                                        ) => void;

                                                                                                                                          function useThrottleFn

                                                                                                                                          useThrottleFn: <T extends noop>(
                                                                                                                                          fn: T,
                                                                                                                                          options?: ThrottleOptions
                                                                                                                                          ) => { run: any; cancel: () => void; flush: () => ReturnType<T> | undefined };

                                                                                                                                            function useTimeout

                                                                                                                                            useTimeout: (fn: () => void, delay?: number) => () => void;

                                                                                                                                              function useTitle

                                                                                                                                              useTitle: (title: string, options?: Options) => void;

                                                                                                                                                function useToggle

                                                                                                                                                useToggle: {
                                                                                                                                                <T = boolean>(): [boolean, Actions<T>];
                                                                                                                                                <T>(defaultValue: T): [T, Actions<T>];
                                                                                                                                                <T, U>(defaultValue: T, reverseValue: U): [T | U, Actions<T | U>];
                                                                                                                                                };

                                                                                                                                                  function useTrackedEffect

                                                                                                                                                  useTrackedEffect: <T extends DependencyList>(
                                                                                                                                                  effect: Effect<T>,
                                                                                                                                                  deps?: [...T]
                                                                                                                                                  ) => void;

                                                                                                                                                    function useUnmount

                                                                                                                                                    useUnmount: (fn: () => void) => void;

                                                                                                                                                      function useUnmountedRef

                                                                                                                                                      useUnmountedRef: () => any;

                                                                                                                                                        function useUpdate

                                                                                                                                                        useUpdate: () => () => void;

                                                                                                                                                          function useVirtualList

                                                                                                                                                          useVirtualList: <T = any>(
                                                                                                                                                          list: T[],
                                                                                                                                                          options: Options<T>
                                                                                                                                                          ) => readonly [{ index: number; data: T }[], (index: number) => void];

                                                                                                                                                            function useWebSocket

                                                                                                                                                            useWebSocket: (socketUrl: string, options?: Options) => Result;

                                                                                                                                                              function useWhyDidYouUpdate

                                                                                                                                                              useWhyDidYouUpdate: (componentName: string, props: IProps) => void;

                                                                                                                                                                Package Files (79)

                                                                                                                                                                Dependencies (9)

                                                                                                                                                                Dev Dependencies (9)

                                                                                                                                                                Peer Dependencies (1)

                                                                                                                                                                Badge

                                                                                                                                                                To add a badge like this onejsDocs.io badgeto your package's README, use the codes available below.

                                                                                                                                                                You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/ahooks.

                                                                                                                                                                • Markdown
                                                                                                                                                                  [![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/ahooks)
                                                                                                                                                                • HTML
                                                                                                                                                                  <a href="https://www.jsdocs.io/package/ahooks"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>