|
1 | 1 | # react-hooks-interval |
2 | 2 |
|
3 | | -Custom React Hooks |
| 3 | +[![NPM version][npm-image]][npm-url] |
| 4 | +[![npm download][download-image]][download-url] |
| 5 | +[![Build Status][travis-image]][travis-url] |
| 6 | + |
| 7 | +Custom React Hooks for setInterval |
| 8 | + |
| 9 | +## Install |
| 10 | + |
| 11 | +>**Note:** The Hooks isn't stable now, the stable version will be available on [Q1 of 2019](https://reactjs.org/blog/2018/11/27/react-16-roadmap.html). |
| 12 | +> |
| 13 | +>Make sure that you have installed the correct version of `react(v16.7.0-alpha.2)` and `react-dom(v16.7.0-alpha.2)`. |
| 14 | +
|
| 15 | +### npm |
| 16 | + |
| 17 | +```bash |
| 18 | +npm install --save @use-hooks/interval |
| 19 | +``` |
| 20 | + |
| 21 | +### yarn |
| 22 | + |
| 23 | +```bash |
| 24 | +yarn add @use-hooks/interval |
| 25 | +``` |
| 26 | + |
| 27 | +## API |
| 28 | + |
| 29 | +### Params |
| 30 | + |
| 31 | +```js |
| 32 | +/** |
| 33 | + * Params |
| 34 | + * @param {function} callback - Custom logic function |
| 35 | + * @param {number|null} delay - Delayed millisecond, stop if null |
| 36 | + */ |
| 37 | +``` |
| 38 | + |
| 39 | +### Returns |
| 40 | + |
| 41 | +```js |
| 42 | +/** |
| 43 | + * Returns |
| 44 | + */ |
| 45 | +``` |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +```js |
| 50 | +import React, { useState } from 'react'; |
| 51 | + |
| 52 | +import useInterval from '@use-hooks/interval/index'; |
| 53 | + |
| 54 | +export default function App() { |
| 55 | + const [count, setCount] = useState(0); |
| 56 | + |
| 57 | + useInterval(() => { |
| 58 | + setCount(count + 1); |
| 59 | + }, 1000); |
| 60 | + |
| 61 | + return ( |
| 62 | + <div> |
| 63 | + <h2>DEMO of <span style={{ color: '#F44336' }}>@use-hooks/interval</span></h2> |
| 64 | + <p>Count: {count}s</p> |
| 65 | + </div> |
| 66 | + ); |
| 67 | +} |
| 68 | + |
| 69 | +``` |
| 70 | + |
| 71 | +[Live Show](https://use-hooks.github.io/react-hooks-interval/) |
| 72 | + |
| 73 | +## Development |
| 74 | + |
| 75 | +> Node >= v8 LTS |
| 76 | +
|
| 77 | + - Clone the project to local disk |
| 78 | + - `npm install` |
| 79 | + - `npm start` |
| 80 | + |
| 81 | +## License |
| 82 | + |
| 83 | +MIT |
| 84 | + |
| 85 | +> Generated by [create-react-hooks](https://github.com/use-hooks/create-react-hooks). |
| 86 | +
|
| 87 | + [npm-image]: https://img.shields.io/npm/v/@use-hooks/interval.svg?style=flat-square |
| 88 | + [npm-url]: https://npmjs.org/package/@use-hooks/interval |
| 89 | + [download-image]: https://img.shields.io/npm/dm/@use-hooks/interval.svg?style=flat-square |
| 90 | + [download-url]: https://npmjs.org/package/@use-hooks/interval |
| 91 | + [travis-url]: https://travis-ci.org/use-hooks/react-hooks-interval |
| 92 | + [travis-image]: https://img.shields.io/travis/use-hooks/react-hooks-interval.svg?style=flat-square |
0 commit comments