New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

simple-use-timer

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simple-use-timer

`simpleUseTimer` is a bare-bones React Hook that helps time events. It returns two functions, one which starts the timer, and one that gets the time elapsed since the start. Calling the start function again will reset the timer.

latest
npmnpm
Version
1.0.3
Version published
Maintainers
1
Created
Source

simpleUseTimer

simpleUseTimer is a bare-bones React Hook that helps time events. It returns two functions, one which starts the timer, and one that gets the time elapsed since the start. Calling the start function again will reset the timer.

version minified size minzipped size downloads build

Install

  • npm install simple-use-timer or
  • yarn add simple-use-timer

Use

import React, { useState } from 'react';
import useTimer from 'simple-use-timer';

const TimerTest = () => {
  const [timeStarted, setTimeStarted] = useState(false);
  const [elapsedTime, setElapsedTime] = useState(0);
  const [startTime, getTime] = useTimer();

  const handleTimerClick = () => {
    if (timeStarted) {
      setElapsedTime(getTime());
    } else {
      startTime();
      setTimeStarted(true);
    }
  };

  return (
    <>
      <button type="button" onClick={handleTimerClick}>
        {timeStarted ? 'Stop Timer' : 'Start Timer'}
      </button>
      {elapsedTime > 0 && <h2>Elapsed time is {elapsedTime / 1000} seconds</h2>}
    </>
  );
};

FAQs

Package last updated on 22 Jun 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts