Forked from loonywizard/react-use-throttle-hook-usage.tsx
Created
September 5, 2023 08:19
-
-
Save Alimjanov-Ibragim/a074b2e9328b2647bf281a33a9fbbc5b to your computer and use it in GitHub Desktop.
Example of usage of React useThrottle hook
This file contains hidden or 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