# react-use-shared-tick

> React hook run function in same setInterval

Latest version **1.1.0** (published 2024-05-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-use-shared-tick
pnpm add react-use-shared-tick
yarn add react-use-shared-tick
bun add react-use-shared-tick
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2024-05-02 |
| First published | 2023-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | ckaznable |

## Links

- npm: https://www.npmjs.com/package/react-use-shared-tick
- Repository: https://github.com/ckaznable/react-use-shared-tick
- Issues: https://github.com/ckaznable/react-use-shared-tick/issues
- npm.io page: https://npm.io/package/react-use-shared-tick

## Recent versions

- 1.1.0 (latest) — 2024-05-02
- 1.0.1 — 2023-01-07
- 1.0.0 — 2023-01-07

## README

[![npm version](https://img.shields.io/npm/v/react-use-shared-tick?color=g)](https://www.npmjs.com/package/react-use-shared-tick)

# React useSharedTick

React hook run function in same `setInterval`

## Installation

use npm
```
npm install react-use-shared-tick --save
```

use yarn
```
yarn add react-use-shared-tick
```

use pnpm
```
pnpm install react-use-shared-tick
```

## Usage

run function per second

```js
import { useStatus } from "react"
import useSharedTick from "react-use-shared-tick"

function App() {
  const [time, setTime] = useState(Date.now())
  useSharedTick(setTime)

  return (
    <div>Current Timestamp: {time}</div>
  )
}
```

run function per 3 second

```jsx
useSharedTick(setTime, {tick: 3000})
```

## API

### useSharedTick

```js
useSharedTick(handler: (t: number)=>void, param)
```

### Handler

| Param | Type | Description |
|---|---|---|
|timestamp|`number`|current timestamp|


### Parameter

| Field | Type | Default | Requirement |Description |
|---|:---:|:---:|:---:|:---:|
| tick | `number` | `1000` | `No` | Running interval time |
| runOnTabVisible | `boolean` | `false` | `No` | when true will pause/start interval if `visibilitychange` event dispatched |

## License
The files included in this repository are licensed under the MIT license.

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