Skip to main content
deleted 28 characters in body
Source Link

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 
function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 
const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

added 32 characters in body
Source Link

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

Stack Overflow is like an encyclopedia, so we prefer to omit these types of phrases. It is assumed that everyone here is trying to be helpful.
Source Link
Dharman
  • 33.9k
  • 27
  • 106
  • 157

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 

Hope that will help someone.

And one more implementation. Custom hook:

function useThrottle (func, delay) { const [timeout, saveTimeout] = useState(null); const throttledFunc = function () { if (timeout) { clearTimeout(timeout); } const newTimeout = setTimeout(() => { func(...arguments); if (newTimeout === timeout) { saveTimeout(null); } }, delay); saveTimeout(newTimeout); } return throttledFunc; } 

and usage:

const throttledFunc = useThrottle(someFunc, 200); 
Source Link
Loading