📜  如何在 react redux js 中添加去抖动 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:59.383000             🧑  作者: Mango

代码示例1
function SearchInput() {
  const [realTimeValue, setRealTimeValue] = useState('');

  const debouncedValue = useDebouncedValue(realTimeValue, 500); // this value will pick real time value, but will change it's result only when it's seattled for 500ms

  useEffect(() => {
    // this effect will be called on seattled values
    api.fetchSearchResults(debouncedValue);
  }, [debouncedValue])

  return  setRealTimeValue(event.target.value)} />
}