react-ref-observe
A React hooks for observing an element resizing and clicking outside
Usage
npm i react-ref-observe
import * as React from "react";import observeResize observeClickOutside from "react-ref-observe"; const Observers = const firstRef = React; const secondRef = React; const clicks setClicks = React; const firstSize = ; ; return <> <div => width: firstSizewidth height: firstSizeheight </div> <div =>Clicks outside: clicks</div> </> ;;
API
observeResize(ref, callback)
Observes element resizing. Uses resize-observer-polyfill
- ref - React reference to a DOM element
- callback optional - callback function, taking argument
{width, height}
Returns an object {width: Number, height: Number}
observeClickOutside(refs, callback)
Observes clicks outside an element
- refs - Array of react references to DOM elements
- callback - callback function, taking click or touch event argument