This file contains 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 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 } from "react"; | |
type GestureType = | |
| "swipeUp" | |
| "swipeDown" | |
| "swipeLeft" | |
| "swipeRight" | |
| "tap" | |
| "pinch" | |
| "zoom"; |
This file contains 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"; | |
interface NetworkInformation extends EventTarget { | |
downlink?: number; | |
effectiveType?: "slow-2g" | "2g" | "3g" | "4g"; | |
rtt?: number; | |
saveData?: boolean; | |
onchange?: EventListener; | |
} |
This file contains 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 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
/** | |
* Custom hook for dynamically resizing a textarea to fit its content. | |
* @param {React.RefObject<HTMLTextAreaElement>} textareaRef - Reference to the textarea element. | |
* @param {string} textContent - Current text content of the textarea. | |
* @param {number} maxHeight - Optional: maxHeight of the textarea in pixels. | |
*/ | |
import { useEffect } from "react"; | |
const useDynamicTextareaSize = ( | |
textareaRef: React.RefObject<HTMLTextAreaElement>, |
This file contains 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, useState } from "react"; | |
// Custom hook to copy text to clipboard | |
const useCopyToClipboard = (timeoutDuration: number = 1000) => { | |
const [copied, setCopied] = useState(false); | |
const [error, setError] = useState<Error | null>(null); | |
const copyToClipboard = useCallback( | |
async (text: string) => { | |
try { |
This file contains 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 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"; | |
function useLocalStorage() { | |
const [loadingStates, setLoadingStates] = useState<Map<string, boolean>>( | |
new Map() | |
); | |
const setStorageValue = <T>(key: string, value: T) => { | |
try { | |
window.localStorage.setItem(key, JSON.stringify(value)); |
This file contains 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"; | |
import resolveConfig from "tailwindcss/resolveConfig"; | |
// Update the path to your Tailwind config file | |
import tailwindConfig from "tailwind.config"; | |
const useTailwindBreakpoint = ({ | |
onBreakpointChange, | |
}: { | |
// eslint-disable-next-line no-unused-vars |
NewerOlder