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

react-clone-referenced-element

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-clone-referenced-element

Clones a React element while preserving its original ref

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
59K
increased by31.11%
Maintainers
1
Weekly downloads
 
Created
Source

cloneReferencedElement for React Tests codecov

This is a version of React.cloneElement that preserves the original element's callback ref even if you specify a new callback ref for the clone.

This library is written for components that use callback refs.

Installation

Install this module from npm:

npm install --save react-clone-referenced-element

This library is written in ES2018. Your JavaScript runtime must support trailing commas in function calls and object spread properties. All modern browsers since 2018 support these features.

You will also need to transform or define a global variable named __DEV__.

Usage

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.

const original =
  <Component ref={component => {
    console.log('Running the original ref handler');
  }} />;
const clone = cloneReferencedElement(original, {
  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

Keywords

FAQs

Package last updated on 09 May 2021

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