You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

use-auto-callback-ref

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-auto-callback-ref

An custom `useCallback` hook which returns a continuously updating ref object. This means the callback ref will always be the latest function. This can be useful for things like event handlers so you don't need to unsubscribe/resubscribe each time the cal

1.0.0
latest
Source
npmnpm
Version published
Weekly downloads
18
5.88%
Maintainers
1
Weekly downloads
 
Created
Source

use-callback-ref

An custom useCallback hook which returns a continuously updating ref object. This means the callback ref will always be the latest function. This can be useful for things like event handlers so you don't need to unsubscribe/resubscribe each time the callback updates.

Usage

import { useCallbackRef } from 'use-callback-ref';

const ref = useCallbackRef(() => {
}, []);

// this is just an example
useEffect(() => {
  // in this case if we were using a normal callback
  // we would have to unsubscribe and re-subscribe each time the handler updates
  // however with a callback ref we can simply call the function contained in the
  // ref, which will always be the latest one and we only have to subscribe once
  return emitter.subscribe(() => {
    ref.current();
  });
}, []);

FAQs

Package last updated on 08 Jan 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts