use-throttled-value
use-throttled-value
값을 스로틀(throttle)해서 반환하는 훅이에요. 지정된 주기(wait 밀리초)마다 마지막 값으로 업데이트돼요.
출처: 문서
본문
사용법 (Usage)
useThrottledValue 훅에 값과 대기 시간을 넘겨주면, 지정된 시간 동안 스로틀된 값을 반환해요:
import { Text, TextInput } from '@mantine/core';
import { useThrottledValue } from '@mantine/hooks';
function Demo() {
const [value, setValue] = useState('');
const throttledValue = useThrottledValue(value, 1000);
return (
<>
setValue(event.currentTarget.value)} />
Throttled value: {throttledValue || '–'}
);
}
정의 (Definition)
function useThrottledValue<T>(value: T, wait: number): T;