Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alimjanov-Ibragim/a074b2e9328b2647bf281a33a9fbbc5b to your computer and use it in GitHub Desktop.
Save Alimjanov-Ibragim/a074b2e9328b2647bf281a33a9fbbc5b to your computer and use it in GitHub Desktop.
Example of usage of React useThrottle hook
import React, { useEffect, useState } from 'react'
import { useThrottle } from './useThrottle'
export default function App() {
const [value, setValue] = useState('hello')
const throttledValue = useThrottle(value)
useEffect(() => console.log(`throttledValue changed: ${throttledValue}`), [
throttledValue,
])
function onChange(event: React.ChangeEvent<HTMLInputElement>) {
setValue(event.target.value)
}
return (
<div>
Input: <input value={value} onChange={onChange} />
<p>Throttled value: {throttledValue}</p>
</div>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment