This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useCallback } from 'react'; | |
| // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type | |
| export function useFunction<T extends Function>(fn: T): T { | |
| const hook = useCallback<any>(function (this: any, ...args: any[]) { | |
| return hook.fn.apply(this, args); | |
| }, []); | |
| hook.fn = fn; | |
| return hook as T; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { useEffect } from 'react' | |
| import { useFunction } from './useFunction' | |
| /** | |
| * Hook to use native event listener | |
| * @param eventName | |
| * @param listener Does not have to be memorized | |
| */ | |
| export function useNativeEvent<K extends keyof GlobalEventHandlersEventMap>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { Dispatch, SetStateAction, useState } from 'react' | |
| import { useConst } from './useConst' | |
| import { useOnUnmount } from './useOnUnmount' | |
| export function useDebouncedState<T>(initialValue: T, delay = 1): [T, Dispatch<SetStateAction<T>>] { | |
| const [debouncedValue, setDebouncedValue] = useState(initialValue) | |
| const api = useConst(() => { | |
| let tempValue = initialValue | |
| let timeout = 0 |
OlderNewer