0.1.0 • Published 4 years ago

@yao-react/use-timeout v0.1.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

@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

proptyperequireddescription
msnull | undefined | boolean | numberfalsethe milliseconds to delay
depsArrayfalse
  • When ms is null | undefined | false | Infinity, it will never done and there will be no timer
  • When ms is true | <0, it is done immediately and there will be no timer