1.0.13 • Published 5 years ago

use-element-position v1.0.13

Weekly downloads
21
License
MIT
Repository
github
Last release
5 years ago

use-element-position

React hook to get bounding client rect

Usage

import { useElementPosition } from 'use-element-position'

const MyComponent = () => {
  const [ref, { width }] = useElementPosition({ width: 0 })

  return (
    <div ref={ref}>
      My width is {width}px
    </div>
  )
}

Or use the wrapper component

import { WithPosition } from 'use-element-position'

const MyComponent = ({ width }) => (
  <div>
    My width is {width}px
  </div>
)

const MyWrapperComponent = () => (
  <WithPosition>
    <MyComponent />
  </WithPosition>
)

You can retrieve all the properties included in getBoundingClientRect : bottom, height, left, right, top, width, x, y You can also retrieve offsetTop and offsetLeft's values of your element.

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago