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

@radix-ui/react-use-callback-ref

Package Overview
Dependencies
Maintainers
6
Versions
72
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@radix-ui/react-use-callback-ref

  • 1.0.1-rc.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
9.4M
increased by3.25%
Maintainers
6
Weekly downloads
 
Created

What is @radix-ui/react-use-callback-ref?

@radix-ui/react-use-callback-ref is a utility hook for React that allows you to create a stable callback reference that always points to the latest version of a function. This is particularly useful in scenarios where you need to pass a callback to a child component or a third-party library, and you want to ensure that the callback always has access to the latest state or props.

What are @radix-ui/react-use-callback-ref's main functionalities?

Stable Callback Reference

This feature allows you to create a stable callback reference that always points to the latest version of a function. In this example, the `handleClick` callback will always log the current count, even if the state changes.

import { useCallbackRef } from '@radix-ui/react-use-callback-ref';

function MyComponent() {
  const [count, setCount] = React.useState(0);

  const handleClick = useCallbackRef(() => {
    console.log('Current count:', count);
  });

  return (
    <div>
      <button onClick={() => setCount(count + 1)}>Increment</button>
      <button onClick={handleClick}>Log Count</button>
    </div>
  );
}

Other packages similar to @radix-ui/react-use-callback-ref

FAQs

Package last updated on 19 May 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

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