useMergeRefs
Aboutβ
Merges any number of refs into a single ref
Installationβ
npm install --save rooks
Importing the hookβ
import { useMergeRefs } from "rooks";
Usageβ
function Demo() {
const mousedownRef = useEventListenerRef("mousedown", () => {
console.log("mouse down");
});
const mouseupRef = useEventListenerRef("mouseup", () => {
console.log("mouse up");
});
const ref = useMergeRefs(mousedownRef, mouseupRef);
return (
<div>
<h1>Rooks : useMergeRefs Example</h1>
<hr></hr>
<div ref={ref}>
A div with multiple refs. Click me!!
</div>
</div>
);
}
render(<Demo />);
Argumentsβ
Argument value | Type | Description |
---|---|---|
refs | Array | Takes any number of refs. Refs can be mutable refs or function refs. |
Returnsβ
Return value | Type | Description |
---|---|---|
ref | CallbackRef | Merged ref |
Codesandbox Examplesβ
Basic Usageβ
Join Bhargav's discord serverβ
You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.