|
Download react-use/docs/useTimeout.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.14 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useTimeout.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/react-use/docs/useTimeout.md
-
curl -L -o useTimeout.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/react-use/docs/useTimeout.md
1.14 kB
useTimeout
Re-renders the component after a specified number of milliseconds.
Provides handles to cancel and/or reset the timeout.
Usage
import { useTimeout } from 'react-use';
function TestComponent(props: { ms?: number } = {}) {
const ms = props.ms || 5000;
const [isReady, cancel] = useTimeout(ms);
return (
<div>
{ isReady() ? 'I\'m reloaded after timeout' : `I will be reloaded after ${ ms / 1000 }s` }
{ isReady() === false ? <button onClick={ cancel }>Cancel</button> : '' }
</div>
);
}
const Demo = () => {
return (
<div>
<TestComponent />
<TestComponent ms={ 10000 } />
</div>
);
};
Reference
const [
isReady: () => boolean | null,
cancel: () => void,
reset: () => void,
] = useTimeout(ms: number = 0);
isReady:()=>boolean|null- function returning current timeout state:false- pending re-rendertrue- re-render performednull- re-render cancelled
cancel:()=>void- cancel the timeout (component will not be re-rendered)reset:()=>void- reset the timeout