Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/alexanderkhivrych/react-use-clock-hook

react-use-clock-hook
https://github.com/alexanderkhivrych/react-use-clock-hook

clock hooks js moment react react-library webpack

Last synced: about 1 month ago
JSON representation

react-use-clock-hook

Awesome Lists containing this project

README

        





react-use-clock-hook ⏰









npm package


npm downloads


> React Hook for sharing clock logic

## Install

```bash
#With npm
npm install react-use-clock-hook --save
```

```bash
#With yarn
yarn add react-use-clock-hook
```

## Usage

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

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

return (



Computer time: {time}


Raw time: {raw.format("dddd, MMMM Do YYYY, h:mm:ss a")}


);
}

export default App;
```

#### `useClock(, )`
Param | Type | Default | Description
--- | --- | --- | ---
format | `String` | `"DD/MM/YYYY HH:mm:ss"` | Any string accepted by [`moment.format`](https://momentjs.com/docs/#/displaying/format/)
period | `Number` | `1000` | Time, in miliseconds, that the clock is updated

## Dependency

[moment](https://github.com/moment/moment)

## License

MIT © [alexanderkhivrych](https://github.com/alexanderkhivrych)