
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-clone-referenced-element
Advanced tools
Clones a React element while preserving its original ref
This is a version of React.cloneElement
that preserves the original element's ref even if you specify a new ref for the clone.
Install this module from npm:
npm install --save react-clone-referenced-element
This library was designed for React Native, so if you are using it with React in other environments, you will need to compile the code first. How you do this is up to you. With Babel, use the following plugins:
You will also need to transform or define a global variable named __DEV__
.
The signature of cloneReferencedElement
is the same as that of React.cloneElement
. However, when using callback refs, it will preserve the ref on the original component if there is one.
let element =
<Component ref={component => {
console.log('Running the original ref handler');
}} />
cloneReferencedElement(element, {
ref(component) {
console.log('Running the clone ref handler');
},
});
When the component is mounted, the console will display:
Running the clone ref handler
Running the original ref handler
1.1.0
React.cloneElement
let
to const
for required modulesFAQs
Clones a React element while preserving its original ref
The npm package react-clone-referenced-element receives a total of 52,747 weekly downloads. As such, react-clone-referenced-element popularity was classified as popular.
We found that react-clone-referenced-element demonstrated a not healthy version release cadence and project activity because the last version was released 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.