Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@radix-ui/react-use-callback-ref
Advanced tools
@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.
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>
);
}
The `use-latest` package provides a hook that returns a mutable ref object containing the latest value. This is similar to `@radix-ui/react-use-callback-ref` in that it helps to keep a stable reference to the latest value, but it is more general-purpose and can be used for any value, not just functions.
The `use-event-callback` package provides a hook that returns a stable callback reference, similar to `@radix-ui/react-use-callback-ref`. It ensures that the callback always has access to the latest state or props, making it useful for event handlers and other callback scenarios.
The `react-use` package is a collection of essential React hooks, including `useLatest` and `useEventCallback`, which provide similar functionality to `@radix-ui/react-use-callback-ref`. It offers a broader range of hooks for various use cases, making it a more comprehensive utility library.
react-use-callback-ref
$ yarn add @radix-ui/react-use-callback-ref
# or
$ npm install @radix-ui/react-use-callback-ref
This is an internal utility, not intended for public usage.
FAQs
Unknown package
The npm package @radix-ui/react-use-callback-ref receives a total of 6,077,105 weekly downloads. As such, @radix-ui/react-use-callback-ref popularity was classified as popular.
We found that @radix-ui/react-use-callback-ref demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.