Declarative React hook for setTimeout
Demo on CodeSandbox
Declarative adaptation of setTimeout
based on Dan Abramov's blog post about setInterval
npm install use-timeout
import useTimeout from 'use-timeout'
function SimpleExample() {
const [message, setMessage] = useState('changing in 2 seconds...')
useTimeout(() => setMessage('changed!'), 2000)
return <div>{message}</div>
}
Long answer long: overreacted.io/making-setinterval-declarative-with-react-hooks/
⭐ this repo
MIT © siddharthkp