Socket
Socket
Sign inDemoInstall

use-composed-ref

Package Overview
Dependencies
3
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    use-composed-ref

React hook which creates a ref function from given refs. Useful when using forwardRef.


Version published
Weekly downloads
1.9M
decreased by-1.95%
Maintainers
1
Install size
2.99 kB
Created
Weekly downloads
 

Package description

What is use-composed-ref?

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.

What are use-composed-ref's main functionalities?

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>;
}

Other packages similar to use-composed-ref

Readme

Source

use-composed-ref

React hook which creates a ref function from given refs. Useful when using forwardRef.

FAQs

Last updated on 22 Apr 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc