Skip to content

alexanderkhivrych/react-use-clock-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


react-use-clock-hook ⏰



npm package npm downloads

React Hook for sharing clock logic

Install

#With npm
npm install react-use-clock-hook --save 
#With yarn
yarn add react-use-clock-hook

Usage

import React from 'react';
import useClock from 'react-use-clock-hook';

const App = () => {
  const { time, raw } = useClock("HH:mm:ss");

  return (
    <div>
      <div><b>Computer time:</b> {time}</div>
      <div><b>Raw time:</b> {raw.format("dddd, MMMM Do YYYY, h:mm:ss a")}</div>
    </div>
  );
}

export default App;

useClock(<format: String>, <period: Number>)

Param Type Default Description
format String "DD/MM/YYYY HH:mm:ss" Any string accepted by moment.format
period Number 1000 Time, in miliseconds, that the clock is updated

Dependency

moment

License

MIT © alexanderkhivrych