/usePosition

React hook for get position of element

Primary LanguageJavaScriptMIT LicenseMIT

@rehooks/usePosition

React hook for ...

Note: This is using the new React Hooks API Proposal which is subject to change until React 16.7 final.

You'll need to install react, react-dom, etc at ^16.7.0-alpha.0

Install

yarn add @rehooks/usePosition

Usage

import { useRef } from 'react';
import usePosition from '@rehooks/usePosition';

function MyComponent() {
  let ref = useRef(null);
  let { left, top } = usePosition(ref);
  return (
    <p ref={ref}>Hello Hooks: {JSON.stringify({left, top})}</p>
  );
}