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, useState } from "react"; | |
| const defaultEvents = [ | |
| "mousemove", | |
| "mousedown", | |
| "touchstart", | |
| "keydown", | |
| "wheel", | |
| "resize", | |
| ]; |
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, useEffect, useState } from "react"; | |
| // Define custom types for SpeechRecognition and SpeechRecognitionEvent | |
| interface ISpeechRecognitionEvent extends Event { | |
| results: SpeechRecognitionResultList; | |
| resultIndex: number; | |
| } | |
| interface ISpeechRecognition extends EventTarget { | |
| lang: string; |
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, useRef, useState } from "react"; | |
| interface MeasureResult<T extends Element> { | |
| ref: React.RefObject<T>; | |
| bounds: DOMRectReadOnly; | |
| } | |
| const useMeasure = <T extends Element = Element>(): MeasureResult<T> => { | |
| const ref = useRef<T>(null); | |
| const [bounds, setBounds] = useState<DOMRectReadOnly>(new DOMRectReadOnly()); |
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, useEffect, useRef, useState } from "react"; | |
| interface UseBroadcastChannelOptions { | |
| name: string; | |
| onMessage?: (event: MessageEvent) => void; | |
| onMessageError?: (event: MessageEvent) => void; | |
| } | |
| interface UseBroadcastChannelReturn<D, P> { | |
| isSupported: boolean; |
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"; | |
| const Keys = { | |
| Backspace: "Backspace", | |
| Tab: "Tab", | |
| Enter: "Enter", | |
| Shift: "Shift", | |
| Control: "Control", | |
| Alt: "Alt", | |
| Pause: "Pause", |
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, useState } from "react"; | |
| type UseTextSelectionReturn = { | |
| text: string; | |
| rects: DOMRect[]; | |
| ranges: Range[]; | |
| selection: Selection | null; | |
| }; | |
| const getRangesFromSelection = (selection: Selection): Range[] => { |
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, useState } from "react"; | |
| /** | |
| * useDebounce hook | |
| * This hook allows you to debounce any fast changing value. The debounced value will only | |
| * reflect the latest value when the useDebounce hook has not been called for the specified delay period. | |
| * | |
| * @param value - The value to be debounced. | |
| * @param delay - The delay in milliseconds for the debounce. | |
| * @returns The debounced value. |
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, useEffect, useRef, useState } from "react"; | |
| interface UseUndoHook<T> { | |
| value: T; | |
| onChange: (newValue: T) => void; | |
| undo: () => void; | |
| redo: () => void; | |
| clear: () => void; | |
| canUndo: boolean; | |
| canRedo: boolean; |
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, useEffect, useState } from "react"; | |
| interface DeviceOrientationState { | |
| alpha: number | null; | |
| beta: number | null; | |
| gamma: number | null; | |
| absolute: boolean; | |
| } | |
| // Define an extended interface for DeviceOrientationEvent including requestPermission |
NewerOlder