Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-latest-callback

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-latest-callback - npm Package Compare versions

Comparing version 0.1.2 to 0.1.3

2

lib/index.d.ts
/**
* 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc