# react-use-timediff

> React hook to calculate diference between two dates

Latest version **1.0.2** (published 2020-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-timediff
pnpm add react-use-timediff
yarn add react-use-timediff
bun add react-use-timediff
```

## 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.0.2 |
| Published | 2020-09-11 |
| First published | 2020-08-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 1 |
| Unpacked size | 10.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | @adilsonmandlate |
| Maintainers | adilsonmandlate |

## Links

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

## Dependencies (1)

- [rollup-plugin-terser](https://npm.io/package/rollup-plugin-terser.md) ^7.0.2

## Recent versions

- 1.0.2 (latest) — 2020-09-11
- 1.0.1 — 2020-09-09
- 0.1.0 — 2020-08-14
- 1.0.0 — 2020-08-14

## README

# react-use-timediff

> React hook for calculate difference between two dates

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

## Install

Using npm:

```bash
npm install --save react-use-timediff
```

using yarn:

```bash
yarn add react-use-timediff
```

## Usage

```jsx
import React, { Component } from "react";

import { useTimeDiff } from "react-use-timediff";

const Example = () => {
  const date = (new Date(2020, 11, 31,23,59,59));

  const time = useTimeDiff(date, {
    live: true
  });

  return (
    <main>
      <h1>Remaing time to the end of the year: </h1>
      <section>
        <span>Years: {time.years}</span>
        <span>Months: {time.months}</span>
        <span>Days: {time.days}</span>
        <span>Hours: {time.hours}</span>
        <span>Minutes: {time.minutes}</span>
        <span>Seconds: {time.seconds}</span>
      </section>
    </main>;
  )
};
```

## API

```js
useTimeDiff(
  eventDate: Date | number,
  options?: {
    startDate?: Date | number,
    live?: boolean,
    interval?: number
  }
): Object
```

Required:

- `eventDate`: The final date, a Date object or milliseconds, to make the calculation.

Optional:

- `startDate`: The initial date to make the calculations, a Date object or milliseconds. If `live` is true, this will not be used.
  Default: Date.now();

- `live`: Whether it should update the time left, periodically, in the provided interval.
  Default: false;

- `interval`: The periodic update interval of the remaing time, in milliseconds. This will only be used if `live` is set to true.
  Default: 1000;

## License

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

---

This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).

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