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

https://github.com/shu20031026/react-hooks-time-limit

React Hook for get seconds to the target time
https://github.com/shu20031026/react-hooks-time-limit

hooks hooks-api-react react target-time typescript

Last synced: 30 days ago
JSON representation

React Hook for get seconds to the target time

Awesome Lists containing this project

README

          


react-hooks-time-limit

[![npm](https://img.shields.io/npm/v/react-hooks-time-limit.svg?style=flat-square)](https://www.npmjs.com/package/react-hooks-time-limit)


React Hook for get seconds to the target time

![](https://user-images.githubusercontent.com/75605907/149351384-eeabdbb4-4787-4c63-8672-d42cde6e1e5f.gif)

## Instrallation
You can install the package from npm.

```
$ npm install react-hooks-time-limit
```

or

```
$ yarn add react-hooks-time-limit
```

## Usage
This is the simplest example.

```tsx
import React from "react";
import { useTimeLimit } from "react-hooks-time-limit";

const getTomorrow = (): Date => {
const date = new Date(Date.now());
date.setDate(date.getDate() + 1);
return date;
}

const Component: React.FC = () => {
const tomorrow = getTomorrow();
const [ timeLeft, setTargetTime ] = useTimeLimit(tomorrow, { isSec: true });

const handleChangeDate = (event: React.ChangeEvent) => {
const date = new Date(event.target.value)
setTargetTime(date)
}

return (


{timeLeft} seconds left until the target time


change target time




);
};
```

| Parameter | Default | Type | Description |
| :----------------- | :-----: | :-------: | ----------------------------------------------------- |
| intervalTime | `1000` | `int` | Time interval to update the remaining time (optional) |
| isSec | `false` | `boolean` | Returns seconds if true, ms if false (optional) |
## License
[MIT © shu20031026](./LICENSE)