From e80fe2e8c6aa6d032e981fdaf88fd742ba8f9e58 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 15 Jan 2023 12:27:14 -0800 Subject: [PATCH] add debouncing --- src/components/Hero.jsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/components/Hero.jsx b/src/components/Hero.jsx index d19ba1d..8510ea4 100644 --- a/src/components/Hero.jsx +++ b/src/components/Hero.jsx @@ -20,6 +20,7 @@ import Loading from '../img/loading.svg'; export function Hero(props) { const contractAddress = props.contractAddress; const { isConnected, address } = useAccount(); + const [throttled, setThrottled] = useState(''); const [tokensMinted, setTokensMinted] = useState(() => { const saved = localStorage.getItem('tokensMinted-v3-' + address); @@ -58,6 +59,14 @@ export function Hero(props) { function handleStateChange(obj) { setOptions(preState => ({...preState , ...obj})); } + function throttleStateChange(obj) { + const og = throttled; + let t = setTimeout(function() { + setOptions(preState => ({...preState , ...obj})); + }, 600); + setThrottled(t); + clearTimeout(og); + } const defOpt = { address: contractAddress, abi: MainABI, @@ -283,7 +292,7 @@ export function Hero(props) { && ( <> { - handleStateChange({unaboomerAmount: v.target.value}); + throttleStateChange({unaboomerAmount: v.target.value}); radicalizeBoomersWrite.reset() }}>