Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
use-composed-ref
Advanced tools
React hook which creates a ref function from given refs. Useful when using forwardRef.
The npm package 'use-composed-ref' provides a React hook that allows you to compose multiple refs (both React ref objects and callback refs) into a single callback ref. This is particularly useful in scenarios where you need to attach multiple refs to a single element, such as when using third-party libraries that require a ref, while also maintaining your own ref for the same element.
Composing multiple refs
This feature allows the user to combine multiple refs into one, which can then be attached to a React element. In the code sample, `myRef` and `externalRef` are composed into a single ref `composedRef`, which is then used in a div element.
import React, { useRef } from 'react';
import useComposedRef from 'use-composed-ref';
function MyComponent() {
const myRef = useRef(null);
const externalRef = useRef(null);
const composedRef = useComposedRef(myRef, externalRef);
return <div ref={composedRef}>Hello, world!</div>;
}
Similar to 'use-composed-ref', 'react-merge-refs' is another npm package that provides functionality to merge multiple React refs into one. It supports both callback and object refs and is used in a similar way. The main difference lies in the implementation details and possibly in the specific use cases each package is optimized for.
This package offers a way to create a stable callback ref. While it primarily focuses on creating individual callback refs rather than composing multiple refs, it shares the concept of managing refs in a more flexible way, similar to what 'use-composed-ref' offers.
React hook which creates a ref function from given refs. Useful when using forwardRef.
FAQs
React hook which creates a ref function from given refs. Useful when using forwardRef.
The npm package use-composed-ref receives a total of 1,735,095 weekly downloads. As such, use-composed-ref popularity was classified as popular.
We found that use-composed-ref demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer 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
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.