react-timing-hooks
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -5,2 +5,12 @@ # Changelog | ||
## [1.2.0](https://github.com/EricLambrecht/react-timing-hooks/compare/v1.1.1...v1.2.0) (2020-03-27) | ||
### Features | ||
* Make useAnimationFrame and useAnimationFrame loop generic and improve overall typing ([7d69dd8](https://github.com/EricLambrecht/react-timing-hooks/commit/7d69dd8b025c10ece46e0885c330ca67f647c9dd)) | ||
* Make useIdleCallback generic and improve overall typing ([c5282d5](https://github.com/EricLambrecht/react-timing-hooks/commit/c5282d58d2e4dfcf7b379f8afd5db6b405586493)) | ||
* Make useInterval generic and improve overall typing ([3cc08aa](https://github.com/EricLambrecht/react-timing-hooks/commit/3cc08aa27277f826077c4cabe5e98c0467dbb4b0)) | ||
* Make useTimeout generic and improve overall typing ([a65921a](https://github.com/EricLambrecht/react-timing-hooks/commit/a65921a44334e9c9aa511cb89c957822807a04c4)) | ||
### [1.1.1](https://github.com/EricLambrecht/react-timing-hooks/compare/v1.1.0...v1.1.1) (2020-03-21) | ||
@@ -7,0 +17,0 @@ |
@@ -1,6 +0,5 @@ | ||
import { Callback } from '../types'; | ||
/** | ||
* @param callback The callback that is invoked in the next animation frame | ||
*/ | ||
declare const useAnimationFrame: (callback: Callback) => (...args: unknown[]) => void; | ||
declare const useAnimationFrame: <T extends (...args: never[]) => unknown>(callback: T) => (...args: Parameters<T>) => void; | ||
export default useAnimationFrame; |
@@ -1,3 +0,2 @@ | ||
import { Callback } from '../types'; | ||
declare const useAnimationFrameLoop: (callback: Callback, stop?: boolean) => void; | ||
declare const useAnimationFrameLoop: <T extends (...args: never[]) => unknown>(callback: T, stop?: boolean) => void; | ||
export default useAnimationFrameLoop; |
import { RequestIdleCallbackDeadline, RequestIdleCallbackHandle, RequestIdleCallbackOptions } from './types'; | ||
import { Callback } from '../types'; | ||
declare global { | ||
@@ -13,3 +12,3 @@ interface Window { | ||
*/ | ||
declare const useIdleCallback: (callback: Callback, options?: RequestIdleCallbackOptions | undefined) => Callback; | ||
declare const useIdleCallback: <T extends (...args: never[]) => unknown>(callback: T, options?: RequestIdleCallbackOptions | undefined) => (...args: Parameters<T>) => void; | ||
export default useIdleCallback; |
@@ -8,6 +8,4 @@ import useTimeoutEffect from './timeout/useTimeoutEffect'; | ||
import useAnimationFrameLoop from './animation-frame/useAnimationFrameLoop'; | ||
import { IntervalCallback } from './interval/types'; | ||
import { TimeoutEffectCallback } from './timeout/types'; | ||
import { IdleCallbackEffectCallback } from './idle-callback/types'; | ||
import { Callback } from './types'; | ||
export { useAnimationFrame, useAnimationFrameLoop, useIdleCallback, useIdleCallbackEffect, useInterval, useTimeout, useTimeoutEffect, IdleCallbackEffectCallback, IntervalCallback, TimeoutEffectCallback, Callback, }; | ||
export { useAnimationFrame, useAnimationFrameLoop, useIdleCallback, useIdleCallbackEffect, useInterval, useTimeout, useTimeoutEffect, IdleCallbackEffectCallback, TimeoutEffectCallback, }; |
@@ -24,4 +24,4 @@ import { useRef, useCallback, useEffect, useState } from 'react'; | ||
*/ | ||
const useTimeout = (callback, timeout) => { | ||
const timeoutCallback = useRef(() => null); | ||
function useTimeout(callback, timeout) { | ||
const timeoutCallback = useRef(callback); | ||
const [timeoutId, setTimeoutId] = useState(null); | ||
@@ -42,3 +42,3 @@ useEffect(() => { | ||
}, [timeout]); | ||
}; | ||
} | ||
@@ -53,3 +53,3 @@ /** | ||
const useInterval = (callback, delay) => { | ||
const intervalCallback = useRef(() => null); | ||
const intervalCallback = useRef(callback); | ||
useEffect(() => { | ||
@@ -97,3 +97,3 @@ intervalCallback.current = callback; | ||
} | ||
const ricCallback = useRef(() => null); | ||
const ricCallback = useRef(callback); | ||
const [handle, setHandle] = useState(null); | ||
@@ -120,3 +120,3 @@ useEffect(() => { | ||
const useAnimationFrame = (callback) => { | ||
const rafCallback = useRef(() => null); | ||
const rafCallback = useRef(callback); | ||
const [handle, setHandle] = useState(null); | ||
@@ -140,3 +140,3 @@ useEffect(() => { | ||
const useAnimationFrameLoop = (callback, stop = false) => { | ||
const rafCallback = useRef(() => null); | ||
const rafCallback = useRef(callback); | ||
const stopValue = useRef(false); | ||
@@ -143,0 +143,0 @@ useEffect(() => { |
@@ -28,4 +28,4 @@ 'use strict'; | ||
*/ | ||
const useTimeout = (callback, timeout) => { | ||
const timeoutCallback = react.useRef(() => null); | ||
function useTimeout(callback, timeout) { | ||
const timeoutCallback = react.useRef(callback); | ||
const [timeoutId, setTimeoutId] = react.useState(null); | ||
@@ -46,3 +46,3 @@ react.useEffect(() => { | ||
}, [timeout]); | ||
}; | ||
} | ||
@@ -57,3 +57,3 @@ /** | ||
const useInterval = (callback, delay) => { | ||
const intervalCallback = react.useRef(() => null); | ||
const intervalCallback = react.useRef(callback); | ||
react.useEffect(() => { | ||
@@ -101,3 +101,3 @@ intervalCallback.current = callback; | ||
} | ||
const ricCallback = react.useRef(() => null); | ||
const ricCallback = react.useRef(callback); | ||
const [handle, setHandle] = react.useState(null); | ||
@@ -124,3 +124,3 @@ react.useEffect(() => { | ||
const useAnimationFrame = (callback) => { | ||
const rafCallback = react.useRef(() => null); | ||
const rafCallback = react.useRef(callback); | ||
const [handle, setHandle] = react.useState(null); | ||
@@ -144,3 +144,3 @@ react.useEffect(() => { | ||
const useAnimationFrameLoop = (callback, stop = false) => { | ||
const rafCallback = react.useRef(() => null); | ||
const rafCallback = react.useRef(callback); | ||
const stopValue = react.useRef(false); | ||
@@ -147,0 +147,0 @@ react.useEffect(() => { |
@@ -1,2 +0,1 @@ | ||
import { IntervalCallback } from './types'; | ||
/** | ||
@@ -9,3 +8,3 @@ * This hook was inspired by Dan Abramov's blogpost: | ||
*/ | ||
declare const useInterval: (callback: IntervalCallback, delay: number | null) => void; | ||
declare const useInterval: <T extends (...args: never[]) => unknown>(callback: T, delay: number | null) => void; | ||
export default useInterval; |
export declare type TimeoutCreator = (handler: () => unknown, timeout: number) => any; | ||
export declare type TimeoutId = ReturnType<typeof setTimeout>; | ||
export declare type TimeoutCallback = (...args: any[]) => unknown; | ||
export declare type TimeoutEffectCallback = (timeoutFunc: TimeoutCreator) => void | (() => void | undefined); |
@@ -1,2 +0,1 @@ | ||
import { TimeoutCallback } from './types'; | ||
/** | ||
@@ -6,3 +5,3 @@ * @param callback The callback that is invoked after the timeout expired | ||
*/ | ||
declare const useTimeout: (callback: TimeoutCallback, timeout: number) => (...args: unknown[]) => void; | ||
declare function useTimeout<T extends (...args: never[]) => unknown>(callback: T, timeout: number): (...args: Parameters<T>) => void; | ||
export default useTimeout; |
{ | ||
"name": "react-timing-hooks", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "React hooks for setTimeout, setInterval, requestAnimationFrame, requestIdleCallback", | ||
@@ -19,3 +19,3 @@ "main": "dist/index.js", | ||
"build:prod": "rimraf \"./dist\" && rollup -c rollup.config.prod.js", | ||
"release": "cli-confirm \"Do you really want to create a new release? (Y/N)\" && standard-version", | ||
"release": "standard-version --dry-run && cli-confirm \"Do you really want to create a new release? (Y/N)\" && standard-version", | ||
"prepublishOnly": "cli-confirm \"Do you really want to publish the current release? (Y/N)\" && npm run test && npm run build:prod" | ||
@@ -22,0 +22,0 @@ }, |
@@ -1,4 +0,5 @@ | ||
![minified](https://badgen.net/bundlephobia/minzip/react-timing-hooks) | ||
![types](https://badgen.net/npm/types/react-timing-hooks) | ||
![checks](https://badgen.net/github/checks/EricLambrecht/react-timing-hooks) | ||
![npm](https://flat.badgen.net/npm/v/react-timing-hooks) | ||
![minified](https://flat.badgen.net/bundlephobia/minzip/react-timing-hooks) | ||
![types](https://flat.badgen.net/npm/types/react-timing-hooks) | ||
![checks](https://flat.badgen.net/github/checks/EricLambrecht/react-timing-hooks) | ||
@@ -16,5 +17,20 @@ # React Timing Hooks | ||
* Full Typescript support | ||
* [lightweight](https://bundlephobia.com/result?p=react-timing-hooks) (~1KB minzipped, no external dependencies) | ||
* [Lightweight](https://bundlephobia.com/result?p=react-timing-hooks) (less than 1KB minzipped, no external dependencies) | ||
* Tree-shakable | ||
## Installation | ||
```bash | ||
# via npm | ||
npm i react-timing-hooks | ||
# via yarn | ||
yarn add react-timing-hooks | ||
``` | ||
## Usage | ||
```bash | ||
npm i react-timing-hooks | ||
``` | ||
@@ -21,0 +37,0 @@ ```jsx harmony |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28745
127
17
371