@bscop/use-forward-ref
v1.0.2
Published
React hook that permits to use the forwarded ref, or a fallback when it's not provided.
Downloads
371
Maintainers
Readme
use-forward-ref
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