Last active
September 5, 2023 08:19
-
-
Save loonywizard/1c0767462699f29a8a7c9ea3590491de to your computer and use it in GitHub Desktop.
Example of usage of React useThrottle hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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