UNPKG

ik-hooks

Version:

IK hooks is a collection of custom React hooks designed to enhance your development experience by providing useful utilities for common tasks

78 lines (67 loc) 2.56 kB
import * as react from 'react'; import { SetStateAction, FC } from 'react'; import { Socket } from 'socket.io-client'; import * as react_jsx_runtime from 'react/jsx-runtime'; interface RemoveArgsType { reset?: boolean; } type Remove = (options?: RemoveArgsType) => void; type UseLocalStorageReturnType<T> = { value: T; getValue: () => T | null; setValue: (value: T | SetStateAction<T>) => T; removeValue: Remove; }; /** * useLocalStorage React Hook for managing state with local storage. * @template T - The type of the value to be stored. * @param {string} key - The key under which the value is stored. * @param {T} initialValue - The initial value. * @returns {[T, Function]} The current value and a function to update it. */ declare const useLocalStorage: <T>(key: string, initialValue: T) => UseLocalStorageReturnType<T>; type SetValueCallbackType<T> = (prevState: T) => T; /** * useToggle React Hook for managing boolean state. * @param {boolean} initialValue - The initial value. * @returns {[boolean, Function]} The current value and a function to toggle it. */ declare const useToggle: (initialValue?: boolean) => [value: boolean, (value?: boolean | SetValueCallbackType<boolean>) => void]; interface UseSocketEventsProps<T> { callback: (args?: T) => Promise<T> | void; event: string; debug?: boolean; socketProvider?: Socket; } /** * useSocketEvent * "useSocketEvent" is a custom hook that listens to a socket event and executes a callback function when the event is triggered. * @param callback * @param event * @param debug * @param socketProvider */ declare const useSocketEvent: <T>({ callback, event, debug, socketProvider }: UseSocketEventsProps<T>) => void; interface IDialogProps { open: boolean; message?: string; onConfirm: () => void; onCancel?: () => void; } interface IUseConfirmType { message?: string; onConfirm: () => void; onCancel?: () => void; dialog?: FC<IDialogProps>; } declare const useConfirm: ({ onConfirm, onCancel, message, dialog: CustomDialog }: IUseConfirmType) => { toggle: (value?: boolean | SetValueCallbackType<boolean> | undefined) => void; dialog: string | number | boolean | react_jsx_runtime.JSX.Element | Iterable<react.ReactNode> | null | undefined; }; declare const _useAsync: <T, E = Error>(asyncFunction: () => Promise<T>) => { execute: () => void; inProgress: boolean; value: T | null; error: E | null; }; export { _useAsync, useConfirm, useLocalStorage, useSocketEvent, useToggle };