@use-hooks/interval
v1.0.1
Published
Custom React Hooks for setInterval
Downloads
309
Readme
react-hooks-interval
Custom React Hooks for setInterval
Install
Note: Make sure that you have installed the correct version of
react(>= v16.8.0)
andreact-dom(>= v16.8.0)
.
npm
npm install --save @use-hooks/interval
yarn
yarn add @use-hooks/interval
API
Params
/**
* Params
* @param {function} callback - Custom logic function
* @param {number|null} delay - Delayed millisecond, stop if null
*/
Returns
/**
* Returns
*/
Usage
import React, { useState } from 'react';
import useInterval from '@use-hooks/interval';
export default function App() {
const [count, setCount] = useState(0);
useInterval(() => {
setCount(count + 1);
}, 1000);
return (
<div>
<h2>DEMO of <span style={{ color: '#F44336' }}>@use-hooks/interval</span></h2>
<p>Count: {count}s</p>
</div>
);
}
Development
Node >= v8 LTS
- Clone the project to local disk
npm install
npm start
License
MIT
Generated by create-react-hooks.