UNPKG

@bevry/hooks

Version:

Aggregation of react hooks that we use. Such as useInterval, useMetaKey.

35 lines 2.13 kB
/** * After X milliseconds, trigger a state change. * * Use cases for this are: * * 1. Refresh your component every second. For example: `useInterval(1000)` * 2. Refresh your component when the first piece of data inside it expires. For example: `useInterval([milkExpires, breadExpires])` * * @param interval The desired interval specified in milliseconds. If an array, then the smallest non-negative number is used. If the interval is negative, then it is discarded, as it is considered no longer relevant. * @param threshold If the interval is valid and below the threshold, then round up to the threshold. For example: `useInterval(300, 1000)` will set the interval to `1000`, and `useInterval(-300, 1000)` still correctly discards the interval. Example use case: A threshold of `1000` would be used to prevent `useInterval(1)` from causing a thousand state changes within a single second, as such, you should set the threshold to the milliseconds that a state change is visually unnecessary. * * @returns An aimless value to cause state to change, it currently represents the number of fulfilled interval completions. */ export declare function useInterval(interval: number | number[], threshold?: number): number; /** * Create an effect for the keydown and keyup events. * @param callback The callback that is fired when a key is pressed */ export declare function useKey(callback: (e: KeyboardEvent) => any): void; /** * Create a state that reflects the status of meta keys. * @param callback The callback that is fired when the state of a meta key changes. */ export declare function useMetaKey(callback: (active: boolean) => any): void; /** * Create an effect for when a key is pressed. * @param callback The callback that is fired when a key is pressed. */ export declare function useKeyPress(callback: (e: KeyboardEvent) => any): void; /** * Create an effect for when the escape key is pressed. * @param callback The callback that is fired when the escape key is pressed. */ export declare function useEscapeKey(callback: (e: KeyboardEvent) => any): void; //# sourceMappingURL=index.d.ts.map