/react-timer

Primary LanguageTypeScriptMIT LicenseMIT

react-timer

GitHub license npm version codecov build status

This react timer component is very simple!

Install

npm install @shhhplus/react-timer --save

How to use

sync

import Timer from '@shhhplus/react-timer';

const Demo = () => {
  const onElapsed = () => {
    console.log('...');
  };
  return <Timer interval={1000} onElapsed={onElapsed} />;
};

async

import Timer from '@shhhplus/react-timer';

const Demo = () => {
  const onElapsed = () => {
    console.log('...');
    return new Promise((resolve) => {
      setTimeout(resolve, 100);
    });
  };
  return <Timer interval={1000} onElapsed={onElapsed} />;
};