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.
The merge-refs npm package is a utility for combining multiple React refs into a single ref. This is particularly useful when you need to pass multiple refs to a single component or element.
Combining Multiple Refs
This feature allows you to combine multiple refs into a single ref. In this example, `ref1` and `ref2` are combined and passed to a `div` element.
import React, { useRef } from 'react';
import mergeRefs from 'merge-refs';
const MyComponent = () => {
const ref1 = useRef();
const ref2 = useRef();
return <div ref={mergeRefs([ref1, ref2])}>Hello World</div>;
};
The react-merge-refs package provides similar functionality by allowing you to merge multiple refs into one. It is very similar to merge-refs in terms of usage and purpose.
A function that merges React refs into one. Filters out invalid (eg. falsy) refs as well and returns original ref if only one valid ref was given.
npm install merge-refs
or yarn add merge-refs
.import mergeRefs from 'merge-refs'
.ref
like so: <div ref={mergeRefs(ref, someOtherRef)} />
createRef()
useRef()
function Hello() {
const ref1 = useRef<HTMLDivElement>(); // I'm going to be updated!
const ref2 = (element: HTMLDivElement) => {
// I'm going to be called!
};
return <div ref={mergeRefs(ref1, ref2)} />;
}
The MIT License.
Wojciech Maj |
FAQs
A function that merges React refs into one.
We found that merge-refs 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.