# use-clock

> React Hook for sharing clock logic with timezone capabilities

Latest version **1.1.0** (published 2019-05-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install use-clock
pnpm add use-clock
yarn add use-clock
bun add use-clock
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2019-05-03 |
| First published | 2019-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 2 |
| Unpacked size | 2.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | rafaelquintanilha |
| Maintainers | rafaelquintanilha |
| Keywords | react-hooks, hooks, react, utils, lib, clock, timer |

## Links

- npm: https://www.npmjs.com/package/use-clock
- Repository: https://github.com/rafaelquintanilha/use-clock
- Homepage: https://github.com/rafaelquintanilha/use-clock#readme
- Issues: https://github.com/rafaelquintanilha/use-clock/issues
- npm.io page: https://npm.io/package/use-clock

## Dependencies (2)

- [use-interval](https://npm.io/package/use-interval.md) ^1.1.0
- [moment-timezone](https://npm.io/package/moment-timezone.md) ^0.5.23

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2019-05-03
- 1.0.2 — 2019-05-03
- 1.0.1 — 2019-02-22
- 1.0.0 — 2019-02-22

## README

# use-clock

> React Hook for sharing clock logic with timezone capabilities

[![NPM](https://img.shields.io/npm/v/use-clock.svg)](https://www.npmjs.com/package/use-clock) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save use-clock
```

## Usage

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

function App() {
  const { time, onTimezone, raw } = useClock("HH:mm:ss");
  const londonTime = onTimezone("Europe/London");
  const brasiliaTime = onTimezone("America/Sao_Paulo");
  return (
    <div>
      <div><b>Computer time:</b> {time}</div>
      <div><b>London time:</b> {londonTime}</div>
      <div><b>Brasilia time:</b> {brasiliaTime}</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`](https://momentjs.com/docs/#/displaying/format/)
period | `Number` | `1000` | Time, in miliseconds, that the clock is updated

#### `onTimezone(<timezone: String>)`
Param | Type | Default | Description
--- | --- | --- | ---
timezone | `String` | Computer timezone as per `moment.tz.guess()` | [Any string accepted as a timezone](//en.wikipedia.org/wiki/List_of_tz_database_time_zones)

## Dependency

This package has [moment-timezone](https://github.com/moment/moment-timezone) as a dependency, which increases the bundle size significantly. **Beware if it's a concern!**

In the future, we may switch to a more lightweight dependency such as [date-fns](https://date-fns.org/). Feel free to contribute!

## License

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

---
_Source: https://npm.io/package/use-clock · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
