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

react-with-forwarded-ref

Package Overview
Dependencies
Maintainers
0
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-with-forwarded-ref

React higher-order component (HOC) for ref forwarding

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11K
increased by5.6%
Maintainers
0
Weekly downloads
 
Created
Source

react-with-forwarded-ref

npm version npm downloads bundlephobia size All Contributors

This React.js higher-order component (HOC) exists to provide an appropriate wrapper for components that utilize forwarded refs. It accepts a ref via props and renames ref to forwardedRef along with whatever other props are passed in.

Installation

npm i react-with-forwarded-ref

or

yarn add react-with-forwarded-ref

Usage

Let's say you have a react component named Comp:

// Comp.js file

const Comp = ({ children, className }) => (
  <div className={className}>
    {children}
  </div>
)

export default Comp

If you're using React.createRef() and want to pass this ref to a child component, you need to utilize forwarded refs. This component handles all the hassle by using the higher-order component (HOC) pattern to wrap your component, accept the ref, and forward it to you as forwardedRef.

// Comp.js file

import withForwardedRef from 'react-with-forwarded-ref'

const Comp = ({ children, className, forwardedRef }) => (
  <div className={className} ref={forwardedRef}>
    {children}
  </div>
)

export default withForwardedRef(Comp)

Contributors

Thanks goes to these wonderful people (emoji key):


Robert Pearce

💻 📖 💡 🤔 ⚠️

Kristián Žuffa

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

Keywords

FAQs

Package last updated on 30 Jun 2024

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