Skip to content

Latest commit

 

History

History
76 lines (54 loc) · 1.45 KB

README.md

File metadata and controls

76 lines (54 loc) · 1.45 KB

Timer hook

Back

Table of Contents

Usage

Starting the timer:

import React from 'react';
import { useTimer } from 'library-react-hooks';

const Example: React.FC = () => {
  const { setTimer} = useTimer();

  return (
    <div>
      <button onClick={() => setTimer(10, { name: 'myTimer', autoFinish: true, callback: () => { console.log('finish') } })}>Button</button>
    </div>
  );
};

Attention! The component will be rerendered every second:

import React from 'react';
import { useListenTime } from 'library-react-hooks';

const Example: React.FC = () => {
  const time = useListenTime();
  const { setTimer} = useTimer();

  return (
    <div>
      <p>My time: {time.timer1}</p>
      <button onClick={() => setTimer(10, { name: 'timer1', observe: true, listen: true })}>Button</button>
    </div>
  );
};

Properties

Set Once timerSettings

timerSettings({ ... });
name type default what`s doing

Fn: on

const { on } = useTimer();

on((event: TTimerEvent) => {
  ...
});

This function listens for the events of adding and deleting messages. Data contains: ...