@yao-react/use-timeout
React hook to treat timeout effect as state.
Philosophy
Effect as state.
Install
npm install @yao-react/use-timeout
yarn add @yao-react/use-timeout
Getting started
import { useTimeout } from '@yao-react/use-timeout';
const Demo = () => {
const done = useTimeout(1000);
return <div>{done ? 'Done' : 'Not yet'}</div>;
};
API
prop | type | required | description |
---|---|---|---|
ms | null | undefined | boolean | number | false | the milliseconds to delay |
deps | Array | false |
- When
ms
isnull | undefined | false | Infinity
, it will never done and there will be no timer - When
ms
istrue | <0
, it is done immediately and there will be no timer