跳至主要内容

useThrottle

對值進行節流的React hook

Usage

即時編輯器

function Demo() {
  const [value, setValue] = useState<string>();
  const throttledValue = useThrottle(value, 500);

  return (
    <div>
      <input
        value={value}
        onChange={e => setValue(e.target.value)}
        placeholder="輸入值"
        style={{ width: 280 }}
      />
      <p style={{ marginTop: 16 }}>節流值:{throttledValue}</p>
    </div>
  );
};

結果

節流值:

API

useThrottle

Returns

T

Arguments

參數名描述類型預設值
value要节流的值T (必填)-
wait间隔时间number | undefined-
options传递给 lodash.throttle 的选项_.ThrottleSettings | undefined-
Squarespace
Squarespace makes your marketing, customer management, and checkout flow effortless—all on a single platform.
Get Started