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

solid-js-timers

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

solid-js-timers

Timer hooks for solid-js.

latest
Source
npmnpm
Version
1.0.2
Version published
Maintainers
1
Created
Source

solid-js-timers

solid-js-timers

pnpm

Timer hooks for solid-js.

Quick start

Installation

npm i solid-js-timers
# or
yarn add solid-js-timers
# or
pnpm add solid-js-timers

Demo here!

Examples

useStopwatch

import { useStopwatch } from 'solid-js-timers';

const App = () => {
  const stopwatch = useStopwatch();
  stopwatch.setMilliseconds(() => 69_000);

  return (
    <div>
      <div>
        <button type="button" onClick={() => stopwatch.start()}>
          start
        </button>
        <button type="button" onClick={() => stopwatch.stop()}>
          stop
        </button>
        <button type="button" onClick={() => stopwatch.reset()}>
          reset
        </button>
      </div>
      <div>
        <span>
          {`${stopwatch.minutes}`.padStart(2, '0')}:
          {`${stopwatch.seconds}`.padStart(2, '0')}:
          {`${stopwatch.milliseconds}`.padStart(2, '0').slice(-2)}
        </span>
      </div>
    </div>
  );
};

Options

OptionDescription
millisecondsCurrent number of milliseconds.
secondsCurrent amount of seconds.
minutesCurrent amount of minutes.
isRunningIndicates whether the timer is running or not.
setMillisecondsSets the number of milliseconds.
startStart timer.
stopStop timer.
resetReset timer.
onListener method that fires on the specified timer event. Available events: start, stop, reset, update.

NOTE

useStopwatch resets after reaching 3600000 milliseconds (60 minutes or 1 hour).

useTime

import { useTime } from 'solid-js-timers';

const App = () => {
  const time = useTime();
  time.start();
  const enUS_DateTimeFormat = Intl.DateTimeFormat('en-US', {
    second: 'numeric',
    minute: 'numeric',
    hour: 'numeric',
    hour12: false,
  });

  return (
    <div>
      <div>
        <button type="button" onClick={() => time.start()}>
          start
        </button>
        <button type="button" onClick={() => time.stop()}>
          stop
        </button>
      </div>
      <div>
        <span>
          {enUS_DateTimeFormat.format(time.currentDate)}
        </span>
        <span>
          {time.ampm}
        </span>
      </div>
    </div>
  );
};

Options

OptionDescription
currentDateCurrent date object.
ampm'AM' or 'PM' depends on time.
isRunningIndicates whether the timer is running or not.
startStart timer.
stopStop timer.
onListener method that fires on the specified timer event. Available events: start, stop, update.

useTimer

import { useTimer } from 'solid-js-timers';

const App = () => {
  const timer = useTimer();
  timer.setMilliseconds(() => 69_000);

  return (
    <div>
      <div>
        <button type="button" onClick={() => timer.start()}>
          start
        </button>
        <button type="button" onClick={() => timer.stop()}>
          stop
        </button>
        <button type="button" onClick={() => timer.reset()}>
          reset
        </button>
      </div>
      <div>
        <span>
          {`${stopwatch.days}`.padStart(2, '0')}:
          {`${stopwatch.hours}`.padStart(2, '0')}:
          {`${stopwatch.minutes}`.padStart(2, '0')}:
          {`${stopwatch.seconds}`.padStart(2, '0')}:
          {`${stopwatch.milliseconds}`.padStart(2, '0').slice(-2)}
        </span>
      </div>
    </div>
  );
};

Options

OptionDescription
millisecondsCurrent number of milliseconds left.
secondsCurrent amount of seconds left.
minutesCurrent amount of minutes left.
hoursCurrent amount of hours left.
daysCurrent amount of days left.
isRunningIndicates whether the timer is running or not.
setMillisecondsSets the number of milliseconds.
startStart timer.
stopStop timer.
resetReset timer.
onListener method that fires on the specified timer event. Available events: start, end, stop, reset, update.

NOTE

useStopwatch, useTime, useTimer have the following arguments.

NameDescriptionDefault value
autoClearIntervalClear timer's interval on cleanup method.true
autoClearTimerClear timer on cleanup method.true
autoClearListenersClear timer's listeners on cleanup method.true
autoClearListersArgsClear arguments of timer's listeners on cleanup method.true
autoClearStoreClear timer store on cleanup method.true

Keywords

solid

FAQs

Package last updated on 04 Sep 2023

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