repo stringlengths 7 64 | file_url stringlengths 81 338 | file_path stringlengths 5 257 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:25:31 2026-01-05 01:50:38 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useTitle.ts | src/useTitle.ts | import { useEffect, useRef } from 'react';
export interface UseTitleOptions {
restoreOnUnmount?: boolean;
}
const DEFAULT_USE_TITLE_OPTIONS: UseTitleOptions = {
restoreOnUnmount: false,
};
function useTitle(title: string, options: UseTitleOptions = DEFAULT_USE_TITLE_OPTIONS) {
const prevTitleRef = useRef(docum... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useKeyPress.ts | src/useKeyPress.ts | import { useState } from 'react';
import useKey, { KeyFilter } from './useKey';
const useKeyPress = (keyFilter: KeyFilter) => {
const [state, set] = useState<[boolean, null | KeyboardEvent]>([false, null]);
useKey(keyFilter, (event) => set([true, event]), { event: 'keydown' }, [state]);
useKey(keyFilter, (event)... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLatest.ts | src/useLatest.ts | import { useRef } from 'react';
const useLatest = <T>(value: T): { readonly current: T } => {
const ref = useRef(value);
ref.current = value;
return ref;
};
export default useLatest;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useDefault.ts | src/useDefault.ts | import { useState } from 'react';
const useDefault = <TStateType>(
defaultValue: TStateType,
initialValue: TStateType | (() => TStateType)
) => {
const [value, setValue] = useState<TStateType | undefined | null>(initialValue);
if (value === undefined || value === null) {
return [defaultValue, setValue] as... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLockBodyScroll.ts | src/useLockBodyScroll.ts | import { RefObject, useEffect, useRef } from 'react';
import { isBrowser, off, on } from './misc/util';
export function getClosestBody(
el: Element | HTMLElement | HTMLIFrameElement | null
): HTMLElement | null {
if (!el) {
return null;
} else if (el.tagName === 'BODY') {
return el as HTMLElement;
} el... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLogger.ts | src/useLogger.ts | import useEffectOnce from './useEffectOnce';
import useUpdateEffect from './useUpdateEffect';
const useLogger = (componentName: string, ...rest) => {
useEffectOnce(() => {
console.log(`${componentName} mounted`, ...rest);
return () => console.log(`${componentName} unmounted`);
});
useUpdateEffect(() => ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSize.tsx | src/useSize.tsx | import * as React from 'react';
import { isBrowser, off, on } from './misc/util';
const { useState, useEffect, useRef } = React;
const DRAF = (callback: () => void) => setTimeout(callback, 35);
export type Element = ((state: State) => React.ReactElement<any>) | React.ReactElement<any>;
export interface State {
wi... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMedia.ts | src/useMedia.ts | import { useEffect, useState } from 'react';
import { isBrowser } from './misc/util';
const getInitialState = (query: string, defaultState?: boolean) => {
// Prevent a React hydration mismatch when a default value is provided by not defaulting to window.matchMedia(query).matches.
if (defaultState !== undefined) {
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSet.ts | src/useSet.ts | import { useCallback, useMemo, useState } from 'react';
export interface StableActions<K> {
add: (key: K) => void;
remove: (key: K) => void;
toggle: (key: K) => void;
reset: () => void;
clear: () => void;
}
export interface Actions<K> extends StableActions<K> {
has: (key: K) => boolean;
}
const useSet = ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useKeyboardJs.ts | src/useKeyboardJs.ts | import { useEffect, useState } from 'react';
import useMount from './useMount';
const useKeyboardJs = (combination: string | string[]) => {
const [state, set] = useState<[boolean, null | KeyboardEvent]>([false, null]);
const [keyboardJs, setKeyboardJs] = useState<any>(null);
useMount(() => {
import('keyboar... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useInterval.ts | src/useInterval.ts | import { useEffect, useRef } from 'react';
const useInterval = (callback: Function, delay?: number | null) => {
const savedCallback = useRef<Function>(() => {});
useEffect(() => {
savedCallback.current = callback;
});
useEffect(() => {
if (delay !== null) {
const interval = setInterval(() => sa... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMediaDevices.ts | src/useMediaDevices.ts | import { useEffect, useState } from 'react';
import { isNavigator, noop, off, on } from './misc/util';
const useMediaDevices = () => {
const [state, setState] = useState({});
useEffect(() => {
let mounted = true;
const onChange = () => {
navigator.mediaDevices
.enumerateDevices()
.t... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useEvent.ts | src/useEvent.ts | import { useEffect } from 'react';
import { isBrowser, off, on } from './misc/util';
export interface ListenerType1 {
addEventListener(name: string, handler: (event?: any) => void, ...args: any[]);
removeEventListener(name: string, handler: (event?: any) => void, ...args: any[]);
}
export interface ListenerType2... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useHoverDirty.ts | src/useHoverDirty.ts | import { RefObject, useEffect, useState } from 'react';
import { off, on } from './misc/util';
// kudos: https://usehooks.com/
const useHoverDirty = (ref: RefObject<Element>, enabled: boolean = true) => {
if (process.env.NODE_ENV === 'development') {
if (typeof ref !== 'object' || typeof ref.current === 'undefin... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePromise.ts | src/usePromise.ts | import { useCallback } from 'react';
import useMountedState from './useMountedState';
export type UsePromise = () => <T>(promise: Promise<T>) => Promise<T>;
const usePromise: UsePromise = () => {
const isMounted = useMountedState();
return useCallback(
(promise: Promise<any>) =>
new Promise<any>((resolv... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSpring.ts | src/useSpring.ts | import { useEffect, useMemo, useState } from 'react';
import { Spring, SpringSystem } from 'rebound';
const useSpring = (targetValue: number = 0, tension: number = 50, friction: number = 3) => {
const [spring, setSpring] = useState<Spring | null>(null);
const [value, setValue] = useState<number>(targetValue);
/... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSpeech.ts | src/useSpeech.ts | import { useCallback, useEffect, useRef, useState } from 'react';
type SpeechOptions = {
lang: string;
voice?: SpeechSynthesisVoice;
rate: number;
pitch: number;
volume: number;
};
export type ISpeechOptions = Partial<SpeechOptions>;
export type VoiceInfo = Pick<SpeechSynthesisVoice, 'lang' | 'name'>;
exp... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMeasureDirty.ts | src/useMeasureDirty.ts | import { RefObject, useEffect, useRef, useState } from 'react';
import ResizeObserver from 'resize-observer-polyfill';
export interface ContentRect {
width: number;
height: number;
top: number;
right: number;
left: number;
bottom: number;
}
const useMeasureDirty = (ref: RefObject<HTMLElement>): ContentRec... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMethods.ts | src/useMethods.ts | import { Reducer, useMemo, useReducer } from 'react';
type Action = {
type: string;
payload?: any;
};
type CreateMethods<M, T> = (state: T) => {
[P in keyof M]: (payload?: any) => T;
};
type WrappedMethods<M> = {
[P in keyof M]: (...payload: any) => void;
};
const useMethods = <M, T>(
createMethods: Creat... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePermission.ts | src/usePermission.ts | import { useEffect, useState } from 'react';
import { noop, off, on } from './misc/util';
export type IState = PermissionState | '';
interface IPushPermissionDescriptor extends PermissionDescriptor {
name: 'push';
userVisibleOnly?: boolean;
}
interface IMidiPermissionDescriptor extends PermissionDescriptor {
n... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSearchParam.ts | src/useSearchParam.ts | import { useEffect, useState } from 'react';
import { isBrowser, off, on } from './misc/util';
const getValue = (search: string, param: string) => new URLSearchParams(search).get(param);
export type UseQueryParam = (param: string) => string | null;
const useSearchParam: UseQueryParam = (param) => {
const location ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useStartTyping.ts | src/useStartTyping.ts | import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
import { off, on } from './misc/util';
const isFocusedElementEditable = () => {
const { activeElement, body } = document;
if (!activeElement) {
return false;
}
// If not element has focus, we assume it is not editable, too.
if (active... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useDropArea.ts | src/useDropArea.ts | import { useMemo, useState } from 'react';
import useMountedState from './useMountedState';
import { noop } from './misc/util';
export interface DropAreaState {
over: boolean;
}
export interface DropAreaBond {
onDragOver: React.DragEventHandler;
onDragEnter: React.DragEventHandler;
onDragLeave: React.DragEven... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useHover.ts | src/useHover.ts | import * as React from 'react';
import { noop } from './misc/util';
const { useState } = React;
export type Element = ((state: boolean) => React.ReactElement<any>) | React.ReactElement<any>;
const useHover = (element: Element): [React.ReactElement<any>, boolean] => {
const [state, setState] = useState(false);
c... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useShallowCompareEffect.ts | src/useShallowCompareEffect.ts | import { DependencyList, EffectCallback } from 'react';
import { equal as isShallowEqual } from 'fast-shallow-equal';
import useCustomCompareEffect from './useCustomCompareEffect';
const isPrimitive = (val: any) => val !== Object(val);
const shallowEqualDepsList = (prevDeps: DependencyList, nextDeps: DependencyList) =... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePageLeave.ts | src/usePageLeave.ts | import { useEffect } from 'react';
import { off, on } from './misc/util';
const usePageLeave = (onPageLeave, args = []) => {
useEffect(() => {
if (!onPageLeave) {
return;
}
const handler = (event) => {
event = event ? event : (window.event as any);
const from = event.relatedTarget || e... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useWait.ts | src/useWait.ts | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false | |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useScroll.ts | src/useScroll.ts | import { RefObject, useEffect } from 'react';
import useRafState from './useRafState';
import { off, on } from './misc/util';
export interface State {
x: number;
y: number;
}
const useScroll = (ref: RefObject<HTMLElement>): State => {
if (process.env.NODE_ENV === 'development') {
if (typeof ref !== 'object... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useIntersection.ts | src/useIntersection.ts | import { RefObject, useEffect, useState } from 'react';
const useIntersection = (
ref: RefObject<HTMLElement>,
options: IntersectionObserverInit
): IntersectionObserverEntry | null => {
const [intersectionObserverEntry, setIntersectionObserverEntry] =
useState<IntersectionObserverEntry | null>(null);
useE... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMotion.ts | src/useMotion.ts | import { useEffect, useState } from 'react';
import { off, on } from './misc/util';
export interface MotionSensorState {
acceleration: {
x: number | null;
y: number | null;
z: number | null;
};
accelerationIncludingGravity: {
x: number | null;
y: number | null;
z: number | null;
};
ro... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useUpsert.ts | src/useUpsert.ts | import useList, { ListActions } from './useList';
import { IHookStateInitAction } from './misc/hookState';
export interface UpsertListActions<T> extends Omit<ListActions<T>, 'upsert'> {
upsert: (newItem: T) => void;
}
/**
* @deprecated Use `useList` hook's upsert action instead
*/
export default function useUpser... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useAsyncFn.ts | src/useAsyncFn.ts | import { DependencyList, useCallback, useRef, useState } from 'react';
import useMountedState from './useMountedState';
import { FunctionReturningPromise, PromiseType } from './misc/types';
export type AsyncState<T> =
| {
loading: boolean;
error?: undefined;
value?: undefined;
}
| {
loa... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useEffectOnce.ts | src/useEffectOnce.ts | import { EffectCallback, useEffect } from 'react';
const useEffectOnce = (effect: EffectCallback) => {
useEffect(effect, []);
};
export default useEffectOnce;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useStateWithHistory.ts | src/useStateWithHistory.ts | import { Dispatch, useCallback, useMemo, useRef, useState } from 'react';
import { useFirstMountState } from './useFirstMountState';
import { IHookStateInitAction, IHookStateSetAction, resolveHookState } from './misc/hookState';
interface HistoryState<S> {
history: S[];
position: number;
capacity: number;
back... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useAsyncRetry.ts | src/useAsyncRetry.ts | import { DependencyList, useCallback, useState } from 'react';
import useAsync, { AsyncState } from './useAsync';
export type AsyncStateRetry<T> = AsyncState<T> & {
retry(): void;
};
const useAsyncRetry = <T>(fn: () => Promise<T>, deps: DependencyList = []) => {
const [attempt, setAttempt] = useState<number>(0);
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useObservable.ts | src/useObservable.ts | import { useState } from 'react';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
export interface Observable<T> {
subscribe: (listener: (value: T) => void) => {
unsubscribe: () => void;
};
}
function useObservable<T>(observable$: Observable<T>): T | undefined;
function useObservable<T>(o... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useQueue.ts | src/useQueue.ts | import { useState } from 'react';
export interface QueueMethods<T> {
add: (item: T) => void;
remove: () => T;
first: T;
last: T;
size: number;
}
const useQueue = <T>(initialValue: T[] = []): QueueMethods<T> => {
const [state, set] = useState(initialValue);
return {
add: (value) => {
set((queue... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useNetworkState.ts | src/useNetworkState.ts | import { useEffect, useState } from 'react';
import { isNavigator, off, on } from './misc/util';
import { IHookStateInitAction } from './misc/hookState';
export interface INetworkInformation extends EventTarget {
readonly downlink: number;
readonly downlinkMax: number;
readonly effectiveType: 'slow-2g' | '2g' | ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useWindowSize.ts | src/useWindowSize.ts | import { useEffect } from 'react';
import useRafState from './useRafState';
import { isBrowser, off, on } from './misc/util';
// Define the type for options that can be passed to the hook
interface Options {
initialWidth?: number; // Initial width of the window (Default value is Infinity)
initialHeight?: number; ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useRaf.ts | src/useRaf.ts | import { useState } from 'react';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
const useRaf = (ms: number = 1e12, delay: number = 0): number => {
const [elapsed, set] = useState<number>(0);
useIsomorphicLayoutEffect(() => {
let raf;
let timerStop;
let start;
const onFrame ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useEnsuredForwardedRef.ts | src/useEnsuredForwardedRef.ts | import {
forwardRef,
ForwardRefExoticComponent,
MutableRefObject,
PropsWithChildren,
PropsWithoutRef,
RefAttributes,
RefForwardingComponent,
useEffect,
useRef,
} from 'react';
export default function useEnsuredForwardedRef<T>(
forwardedRef: MutableRefObject<T>
): MutableRefObject<T> {
const ensur... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMultiStateValidator.ts | src/useMultiStateValidator.ts | import { useCallback, useEffect, useRef, useState } from 'react';
import { StateValidator, UseStateValidatorReturn, ValidityState } from './useStateValidator';
export type MultiStateValidatorStates = any[] | { [p: string]: any } | { [p: number]: any };
export type MultiStateValidator<V extends ValidityState, S extends... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useKey.ts | src/useKey.ts | import { DependencyList, useMemo } from 'react';
import useEvent, { UseEventOptions, UseEventTarget } from './useEvent';
import { noop } from './misc/util';
export type KeyPredicate = (event: KeyboardEvent) => boolean;
export type KeyFilter = null | undefined | string | ((event: KeyboardEvent) => boolean);
export type... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMeasure.ts | src/useMeasure.ts | import { useMemo, useState } from 'react';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
import { isBrowser, noop } from './misc/util';
export type UseMeasureRect = Pick<
DOMRectReadOnly,
'x' | 'y' | 'top' | 'left' | 'right' | 'bottom' | 'height' | 'width'
>;
export type UseMeasureRef<E exte... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useOrientation.ts | src/useOrientation.ts | import { useEffect, useState } from 'react';
import { off, on } from './misc/util';
export interface OrientationState {
angle: number;
type: string;
}
const defaultState: OrientationState = {
angle: 0,
type: 'landscape-primary',
};
const useOrientation = (initialState: OrientationState = defaultState) => {
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLocalStorage.ts | src/useLocalStorage.ts | import { Dispatch, SetStateAction, useCallback, useState, useRef, useLayoutEffect } from 'react';
import { isBrowser, noop } from './misc/util';
type parserOptions<T> =
| {
raw: true;
}
| {
raw: false;
serializer: (value: T) => string;
deserializer: (value: string) => T;
};
const u... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useDeepCompareEffect.ts | src/useDeepCompareEffect.ts | import { DependencyList, EffectCallback } from 'react';
import useCustomCompareEffect from './useCustomCompareEffect';
import isDeepEqual from './misc/isDeepEqual';
const isPrimitive = (val: any) => val !== Object(val);
const useDeepCompareEffect = (effect: EffectCallback, deps: DependencyList) => {
if (process.env... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useNumber.ts | src/useNumber.ts | import useNumber from './useCounter';
export default useNumber;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useIsomorphicLayoutEffect.ts | src/useIsomorphicLayoutEffect.ts | import { useEffect, useLayoutEffect } from 'react';
import { isBrowser } from './misc/util';
const useIsomorphicLayoutEffect = isBrowser ? useLayoutEffect : useEffect;
export default useIsomorphicLayoutEffect;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useCss.ts | src/useCss.ts | import { create, NanoRenderer } from 'nano-css';
import { addon as addonCSSOM, CSSOMAddon } from 'nano-css/addon/cssom';
import { addon as addonVCSSOM, VCSSOMAddon } from 'nano-css/addon/vcssom';
import { cssToTree } from 'nano-css/addon/vcssom/cssToTree';
import { useMemo } from 'react';
import useIsomorphicLayoutEffe... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useTween.ts | src/useTween.ts | import { easing } from 'ts-easing';
import useRaf from './useRaf';
export type Easing = (t: number) => number;
const useTween = (easingName: string = 'inCirc', ms: number = 200, delay: number = 0): number => {
const fn: Easing = easing[easingName];
const t = useRaf(ms, delay);
if (process.env.NODE_ENV !== 'pro... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMountedState.ts | src/useMountedState.ts | import { useCallback, useEffect, useRef } from 'react';
export default function useMountedState(): () => boolean {
const mountedRef = useRef<boolean>(false);
const get = useCallback(() => mountedRef.current, []);
useEffect(() => {
mountedRef.current = true;
return () => {
mountedRef.current = fal... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMouseHovered.ts | src/useMouseHovered.ts | import { RefObject } from 'react';
import useHoverDirty from './useHoverDirty';
import useMouse, { State } from './useMouse';
export interface UseMouseHoveredOptions {
whenHovered?: boolean;
bound?: boolean;
}
const nullRef = { current: null };
const useMouseHovered = (ref: RefObject<Element>, options: UseMouseH... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMediatedState.ts | src/useMediatedState.ts | import { Dispatch, SetStateAction, useCallback, useRef, useState } from 'react';
export interface StateMediator<S = any> {
(newState: any): S;
(newState: any, dispatch: Dispatch<SetStateAction<S>>): void;
}
export type UseMediatedStateReturn<S = any> = [S, Dispatch<SetStateAction<S>>];
export function useMediat... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useRendersCount.ts | src/useRendersCount.ts | import { useRef } from 'react';
export function useRendersCount(): number {
return ++useRef(0).current;
}
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useFullscreen.ts | src/useFullscreen.ts | import { RefObject, useState } from 'react';
import screenfull from 'screenfull';
import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect';
import { noop, off, on } from './misc/util';
export interface FullScreenOptions {
video?: RefObject<
HTMLVideoElement & { webkitEnterFullscreen?: () => void; webk... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useVibrate.ts | src/useVibrate.ts | import { useEffect } from 'react';
import { isNavigator, noop } from './misc/util';
export type VibrationPattern = number | number[];
const isVibrationApiSupported = isNavigator && 'vibrate' in navigator;
function useVibrate(
enabled: boolean = true,
pattern: VibrationPattern = [1000, 1000],
loop: boolean = tr... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useUpdateEffect.ts | src/useUpdateEffect.ts | import { useEffect } from 'react';
import { useFirstMountState } from './useFirstMountState';
const useUpdateEffect: typeof useEffect = (effect, deps) => {
const isFirstMount = useFirstMountState();
useEffect(() => {
if (!isFirstMount) {
return effect();
}
}, deps);
};
export default useUpdateEff... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSessionStorage.ts | src/useSessionStorage.ts | import { useEffect, useState } from 'react';
import { isBrowser } from './misc/util';
const useSessionStorage = <T>(
key: string,
initialValue?: T,
raw?: boolean
): [T, (value: T) => void] => {
if (!isBrowser) {
return [initialValue as T, () => {}];
}
// eslint-disable-next-line react-hooks/rules-of-h... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLongPress.ts | src/useLongPress.ts | import { useCallback, useRef } from 'react';
import { off, on } from './misc/util';
interface Options {
isPreventDefault?: boolean;
delay?: number;
}
const isTouchEvent = (ev: Event): ev is TouchEvent => {
return 'touches' in ev;
};
const preventDefault = (ev: Event) => {
if (!isTouchEvent(ev)) return;
if... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useAsync.ts | src/useAsync.ts | import { DependencyList, useEffect } from 'react';
import useAsyncFn from './useAsyncFn';
import { FunctionReturningPromise } from './misc/types';
export { AsyncState, AsyncFnReturn } from './useAsyncFn';
export default function useAsync<T extends FunctionReturningPromise>(
fn: T,
deps: DependencyList = []
) {
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useRafState.ts | src/useRafState.ts | import { Dispatch, SetStateAction, useCallback, useRef, useState } from 'react';
import useUnmount from './useUnmount';
const useRafState = <S>(initialState: S | (() => S)): [S, Dispatch<SetStateAction<S>>] => {
const frame = useRef(0);
const [state, setState] = useState(initialState);
const setRafState = useC... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useScrolling.ts | src/useScrolling.ts | import { RefObject, useEffect, useState } from 'react';
import { off, on } from './misc/util';
const useScrolling = (ref: RefObject<HTMLElement>): boolean => {
const [scrolling, setScrolling] = useState<boolean>(false);
useEffect(() => {
if (ref.current) {
let scrollingTimeout;
const handleScroll... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePinchZoom.ts | src/usePinchZoom.ts | import { RefObject, useEffect, useMemo, useState } from 'react';
export type CacheRef = {
prevDiff: number;
evCache: Array<PointerEvent>;
};
export enum ZoomState {
'ZOOMING_IN' = 'ZOOMING_IN',
'ZOOMING_OUT' = 'ZOOMING_OUT',
}
export type ZoomStateType = ZoomState.ZOOMING_IN | ZoomState.ZOOMING_OUT;
const u... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useUnmount.ts | src/useUnmount.ts | import { useRef } from 'react';
import useEffectOnce from './useEffectOnce';
const useUnmount = (fn: () => any): void => {
const fnRef = useRef(fn);
// update the ref each render so if it change the newest callback will be invoked
fnRef.current = fn;
useEffectOnce(() => () => fnRef.current());
};
export def... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useDebounce.ts | src/useDebounce.ts | import { DependencyList, useEffect } from 'react';
import useTimeoutFn from './useTimeoutFn';
export type UseDebounceReturn = [() => boolean | null, () => void];
export default function useDebounce(
fn: Function,
ms: number = 0,
deps: DependencyList = []
): UseDebounceReturn {
const [isReady, cancel, reset] =... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useIdle.ts | src/useIdle.ts | import { useEffect, useState } from 'react';
import { throttle } from 'throttle-debounce';
import { off, on } from './misc/util';
const defaultEvents = ['mousemove', 'mousedown', 'resize', 'keydown', 'touchstart', 'wheel'];
const oneMinute = 60e3;
const useIdle = (
ms: number = oneMinute,
initialState: boolean = ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLocation.ts | src/useLocation.ts | import { useEffect, useState } from 'react';
import { isBrowser, off, on } from './misc/util';
const patchHistoryMethod = (method) => {
const history = window.history;
const original = history[method];
history[method] = function (state) {
const result = original.apply(this, arguments);
const event = new... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useThrottle.ts | src/useThrottle.ts | import { useEffect, useRef, useState } from 'react';
import useUnmount from './useUnmount';
const useThrottle = <T>(value: T, ms: number = 200) => {
const [state, setState] = useState<T>(value);
const timeout = useRef<ReturnType<typeof setTimeout>>();
const nextValue = useRef(null) as any;
const hasNextValue =... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useLifecycles.ts | src/useLifecycles.ts | import { useEffect } from 'react';
const useLifecycles = (mount, unmount?) => {
useEffect(() => {
if (mount) {
mount();
}
return () => {
if (unmount) {
unmount();
}
};
}, []);
};
export default useLifecycles;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useScrollbarWidth.ts | src/useScrollbarWidth.ts | import { scrollbarWidth } from '@xobotyi/scrollbar-width';
import { useEffect, useState } from 'react';
export function useScrollbarWidth(): number | undefined {
const [sbw, setSbw] = useState(scrollbarWidth());
// this needed to ensure the scrollbar width in case hook called before the DOM is ready
useEffect((... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useKeyPressEvent.ts | src/useKeyPressEvent.ts | import { Handler, KeyFilter } from './useKey';
import useKeyPressDefault from './useKeyPress';
import useUpdateEffect from './useUpdateEffect';
const useKeyPressEvent = (
key: string | KeyFilter,
keydown?: Handler | null | undefined,
keyup?: Handler | null | undefined,
useKeyPress = useKeyPressDefault
) => {
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMount.ts | src/useMount.ts | import useEffectOnce from './useEffectOnce';
const useMount = (fn: () => void) => {
useEffectOnce(() => {
fn();
});
};
export default useMount;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useHarmonicIntervalFn.ts | src/useHarmonicIntervalFn.ts | import { useEffect, useRef } from 'react';
import { clearHarmonicInterval, setHarmonicInterval } from 'set-harmonic-interval';
const useHarmonicIntervalFn = (fn: Function, delay: number | null = 0) => {
const latestCallback = useRef<Function>(() => {});
useEffect(() => {
latestCallback.current = fn;
});
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useCookie.ts | src/useCookie.ts | import { useCallback, useState } from 'react';
import Cookies from 'js-cookie';
const useCookie = (
cookieName: string
): [string | null, (newValue: string, options?: Cookies.CookieAttributes) => void, () => void] => {
const [value, setValue] = useState<string | null>(() => Cookies.get(cookieName) || null);
con... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useGetSet.ts | src/useGetSet.ts | import { Dispatch, useMemo, useRef } from 'react';
import useUpdate from './useUpdate';
import { IHookStateInitAction, IHookStateSetAction, resolveHookState } from './misc/hookState';
export default function useGetSet<S>(
initialState: IHookStateInitAction<S>
): [get: () => S, set: Dispatch<IHookStateSetAction<S>>] ... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useCopyToClipboard.ts | src/useCopyToClipboard.ts | import writeText from 'copy-to-clipboard';
import { useCallback } from 'react';
import useMountedState from './useMountedState';
import useSetState from './useSetState';
export interface CopyToClipboardState {
value?: string;
noUserInteraction: boolean;
error?: Error;
}
const useCopyToClipboard = (): [CopyToCli... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useClickAway.ts | src/useClickAway.ts | import { RefObject, useEffect, useRef } from 'react';
import { off, on } from './misc/util';
const defaultEvents = ['mousedown', 'touchstart'];
const useClickAway = <E extends Event = Event>(
ref: RefObject<HTMLElement | null>,
onClickAway: (event: E) => void,
events: string[] = defaultEvents
) => {
const sav... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useFavicon.ts | src/useFavicon.ts | import { useEffect } from 'react';
const useFavicon = (href: string) => {
useEffect(() => {
const link: HTMLLinkElement =
document.querySelector("link[rel*='icon']") || document.createElement('link');
link.type = 'image/x-icon';
link.rel = 'shortcut icon';
link.href = href;
document.getElem... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMap.ts | src/useMap.ts | import { useCallback, useMemo, useState } from 'react';
export interface StableActions<T extends object> {
set: <K extends keyof T>(key: K, value: T[K]) => void;
setAll: (newMap: T) => void;
remove: <K extends keyof T>(key: K) => void;
reset: () => void;
}
export interface Actions<T extends object> extends St... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useAudio.ts | src/useAudio.ts | import createHTMLMediaHook from './factory/createHTMLMediaHook';
const useAudio = createHTMLMediaHook<HTMLAudioElement>('audio');
export default useAudio;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/index.ts | src/index.ts | export { default as createMemo } from './factory/createMemo';
export { default as createReducerContext } from './factory/createReducerContext';
export { default as createReducer } from './factory/createReducer';
export { default as createStateContext } from './factory/createStateContext';
export { default as useAsync }... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePreviousDistinct.ts | src/usePreviousDistinct.ts | import { useRef } from 'react';
import { useFirstMountState } from './useFirstMountState';
export type Predicate<T> = (prev: T | undefined, next: T) => boolean;
const strictEquals = <T>(prev: T | undefined, next: T) => prev === next;
export default function usePreviousDistinct<T>(
value: T,
compare: Predicate<T>... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useBeforeUnload.ts | src/useBeforeUnload.ts | import { useCallback, useEffect } from 'react';
import { off, on } from './misc/util';
const useBeforeUnload = (enabled: boolean | (() => boolean) = true, message?: string) => {
const handler = useCallback(
(event: BeforeUnloadEvent) => {
const finalEnabled = typeof enabled === 'function' ? enabled() : tru... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useTimeoutFn.ts | src/useTimeoutFn.ts | import { useCallback, useEffect, useRef } from 'react';
export type UseTimeoutFnReturn = [() => boolean | null, () => void, () => void];
export default function useTimeoutFn(fn: Function, ms: number = 0): UseTimeoutFnReturn {
const ready = useRef<boolean | null>(false);
const timeout = useRef<ReturnType<typeof se... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useFirstMountState.ts | src/useFirstMountState.ts | import { useRef } from 'react';
export function useFirstMountState(): boolean {
const isFirst = useRef(true);
if (isFirst.current) {
isFirst.current = false;
return true;
}
return isFirst.current;
}
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/usePrevious.ts | src/usePrevious.ts | import { useEffect, useRef } from 'react';
export default function usePrevious<T>(state: T): T | undefined {
const ref = useRef<T>();
useEffect(() => {
ref.current = state;
});
return ref.current;
}
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useRafLoop.ts | src/useRafLoop.ts | import { useCallback, useEffect, useMemo, useRef } from 'react';
export type RafLoopReturns = [() => void, () => void, () => boolean];
export default function useRafLoop(
callback: FrameRequestCallback,
initiallyActive = true
): RafLoopReturns {
const raf = useRef<number | null>(null);
const rafActivity = use... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useMouseWheel.ts | src/useMouseWheel.ts | import { useEffect, useState } from 'react';
import { off, on } from './misc/util';
export default () => {
const [mouseWheelScrolled, setMouseWheelScrolled] = useState(0);
useEffect(() => {
const updateScroll = (e: MouseWheelEvent) => {
setMouseWheelScrolled(e.deltaY + mouseWheelScrolled);
};
on(... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useToggle.ts | src/useToggle.ts | import { Reducer, useReducer } from 'react';
const toggleReducer = (state: boolean, nextValue?: any) =>
typeof nextValue === 'boolean' ? nextValue : !state;
const useToggle = (initialValue: boolean): [boolean, (nextValue?: any) => void] => {
return useReducer<Reducer<boolean, any>>(toggleReducer, initialValue);
}... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useError.ts | src/useError.ts | import { useCallback, useEffect, useState } from 'react';
const useError = (): ((err: Error) => void) => {
const [error, setError] = useState<Error | null>(null);
useEffect(() => {
if (error) {
throw error;
}
}, [error]);
const dispatchError = useCallback((err: Error) => {
setError(err);
... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useGetSetState.ts | src/useGetSetState.ts | import { useCallback, useRef } from 'react';
import useUpdate from './useUpdate';
const useGetSetState = <T extends object>(
initialState: T = {} as T
): [() => T, (patch: Partial<T>) => void] => {
if (process.env.NODE_ENV !== 'production') {
if (typeof initialState !== 'object') {
console.error('useGetS... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useTimeout.ts | src/useTimeout.ts | import useTimeoutFn from './useTimeoutFn';
import useUpdate from './useUpdate';
export type UseTimeoutReturn = [() => boolean | null, () => void, () => void];
export default function useTimeout(ms: number = 0): UseTimeoutReturn {
const update = useUpdate();
return useTimeoutFn(update, ms);
}
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useSetState.ts | src/useSetState.ts | import { useCallback, useState } from 'react';
const useSetState = <T extends object>(
initialState: T = {} as T
): [T, (patch: Partial<T> | ((prevState: T) => Partial<T>)) => void] => {
const [state, set] = useState<T>(initialState);
const setState = useCallback((patch) => {
set((prevState) =>
Object.... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useBattery.ts | src/useBattery.ts | import { useEffect, useState } from 'react';
import { isNavigator, off, on } from './misc/util';
import isDeepEqual from './misc/isDeepEqual';
export interface BatteryState {
charging: boolean;
chargingTime: number;
dischargingTime: number;
level: number;
}
interface BatteryManager extends Readonly<BatterySta... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useVideo.ts | src/useVideo.ts | import createHTMLMediaHook from './factory/createHTMLMediaHook';
const useVideo = createHTMLMediaHook<HTMLVideoElement>('video');
export default useVideo;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/useUpdate.ts | src/useUpdate.ts | import { useReducer } from 'react';
const updateReducer = (num: number): number => (num + 1) % 1_000_000;
export default function useUpdate(): () => void {
const [, update] = useReducer(updateReducer, 0);
return update;
}
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/misc/isDeepEqual.ts | src/misc/isDeepEqual.ts | import isDeepEqualReact from 'fast-deep-equal/react';
export default isDeepEqualReact;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/misc/util.ts | src/misc/util.ts | export const noop = () => {};
export function on<T extends Window | Document | HTMLElement | EventTarget>(
obj: T | null,
...args: Parameters<T['addEventListener']> | [string, Function | null, ...any]
): void {
if (obj && obj.addEventListener) {
obj.addEventListener(...(args as Parameters<HTMLElement['addEve... | typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
streamich/react-use | https://github.com/streamich/react-use/blob/9ef95352e459dd2920b0492c63c39863024ee852/src/misc/types.ts | src/misc/types.ts | export type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
export type FunctionReturningPromise = (...args: any[]) => Promise<any>;
| typescript | Unlicense | 9ef95352e459dd2920b0492c63c39863024ee852 | 2026-01-04T15:45:41.983376Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.