@bscop/use-forward-ref
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

use-forward-ref

GitHub license npm version CircleCI Status Coverage

React hook that permits to use the forwarded ref, or a fallback when it's not provided.

Install

npm i @bscop/use-forward-ref

Usage

import React, { useRef } from "react";
import useForwardRef from "@bscop/use-forward-ref";

const Demo = React.forwardRef(
  (props, maybeRef) => {
    /**
     * maybeRef can be a ref, or nothing
     * depending by how the component is used.
     * ref is always a ref, equal to maybeRef
     * only when it is a ref.
     */
    const ref = useForwardRef(maybeRef);

    return (
      <div ref={ref}>
        Demo!
      </div>
    );
  }
);

Contribute

Read the guidelines.

Run tests

npm test

Coverage

Coverage reports are hosted on codecov.

npm run badge:coverage -- --token=<guid>

Bruno Scopelliti
www.brunoscopelliti.com

Package Sidebar

Install

npm i @bscop/use-forward-ref

Weekly Downloads

129

Version

1.0.2

License

MIT

Unpacked Size

8.68 kB

Total Files

9

Last publish

Collaborators

  • brunoscopelliti