TelegramPWA/src/hooks/useStateRef.ts
2023-06-12 11:47:13 +02:00

10 lines
333 B
TypeScript

import { useRef } from '../lib/teact/teact';
// Allows to use state value as "silent" dependency in hooks (not causing updates).
// Also useful for state values that update frequently (such as controlled input value).
export function useStateRef<T>(value: T) {
const ref = useRef<T>(value);
ref.current = value;
return ref;
}