New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

react-combin-refs

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-combin-refs

helps react forward ref to combine and pass the ref even further.

latest
npmnpm
Version
1.0.0
Version published
Maintainers
1
Created
Source

react-combine-refs

There is no built in feature in reactjs that lets you combine react refs. One of the mostly used tool in react is React.forwardRef and it only forwars the ref to the parent component and doesn't allow access to current component the ref.

example:

import React, { useRef } from "react";
import useConbinedRef from "react-combine-refs";

const Button = React.forwardRef((props, fRef) => {
  // pass the forwared ref fRef to the combiner hook
  const cRef = useCombinedRef(fRef);

  // use cRef here ...

  const { children, ...otherProps } = props;
  return (
    <Button ref={cRef} {...otherProps}>
      {children}
    </Button>
  );
});

export default function App() {
  const ref = useRef();

  // use ref here ...

  return (
    <div>
      <Button ref={ref}>Hello</Button>
    </div>
  );
}

Licence

MIT License

Keywords

react

FAQs

Package last updated on 20 Aug 2020

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