use-latest-callback
Advanced tools
Comparing version 0.1.2 to 0.1.3
/** | ||
* React hook which returns the latest callback without changing the reference. | ||
*/ | ||
export default function useLatestCallback<T extends (this: unknown, ...args: unknown[]) => unknown>(callback: T): T; | ||
export default function useLatestCallback<T extends Function>(callback: T): T; |
{ | ||
"name": "use-latest-callback", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "React hook which returns the latest callback without changing the reference", | ||
@@ -5,0 +5,0 @@ "source": "src/index.ts", |
@@ -15,12 +15,13 @@ import React from 'react'; | ||
*/ | ||
export default function useLatestCallback< | ||
T extends (this: unknown, ...args: unknown[]) => unknown | ||
>(callback: T): T { | ||
export default function useLatestCallback<T extends Function>(callback: T): T { | ||
// @ts-expect-error | ||
const ref = React.useRef<T>(throwIfRender); | ||
const latestCallback = React.useRef(function latestCallback(...args) { | ||
const latestCallback = React.useRef(function latestCallback( | ||
this: unknown, | ||
...args: unknown[] | ||
) { | ||
// eslint-disable-next-line babel/no-invalid-this | ||
return ref.current.apply(this, args); | ||
} as T).current; | ||
} as unknown as T).current; | ||
@@ -27,0 +28,0 @@ // @ts-expect-error |
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
64
4646