@dloizides/rn-web-hooks
Cross-platform (React Native + react-native-web) React hooks and rate-limiting
helpers, extracted from the byte-identical copies in katalogos-web and erevna-web.
| Export | What |
|---|---|
useOnlineStatus() | { isOnline, isOffline } via navigator.onLine + online/offline events (web); always online on native |
useEscapeKey(handler, enabled?) | fires handler on Escape keydown (web only, no-op native) |
useHighContrast() | tracks prefers-contrast: more (web only, false native) |
debounce(fn, wait?) | plain debounced function |
throttle(fn, wait?) | plain throttled function |
useDebouncedCallback(cb, wait) | stable debounced callback with .flush() / .cancel(), flushes on unmount |
useDebouncedValue(value, delayMs) | the value once it has stopped changing for delayMs (search boxes, filters) |
Install
npm install @dloizides/rn-web-hooks
Peers: react (>=18), react-native (>=0.79). Runtime dep: @dloizides/utils.
Usage
import { useOnlineStatus, useEscapeKey, useDebouncedCallback, useWakeLock } from '@dloizides/rn-web-hooks';
const { isOffline } = useOnlineStatus();
useEscapeKey(() => setOpen(false), open);
const debouncedSave = useDebouncedCallback((v: string) => save(v), 300);
useWakeLock(trackerOpen);