streamich/react-use

[useMeasure] Ability to track a custom Ref

Open

#1.227 aberto em 18 de mai. de 2020

Ver no GitHub
 (15 comments) (19 reactions) (0 assignees)TypeScript (3.273 forks)batch import
good first issuehelp wanted

Métricas do repositório

Stars
 (43.979 stars)
Métricas de merge de PR
 (Mesclagem média 1743d 9h) (1 fundiu PR em 30d)

Description

Is your feature request related to a problem? Please describe.

Currently useMeasure returns a ref which needs to be assigned a ref in the JSX. This has 2 issues:

  1. The ref is not a real useRef for eg. Does not have ref.current as a prop.
  2. If I already have a component where I have a ref, I just want to track its size changes.

Describe the solution you'd like

An API of this shape: const {width, height ... } = useMeasure({ref: currentRef});

Describe alternatives you've considered

I am using https://github.com/ZeeCoder/use-resize-observer ... in the absence of the above which I want to remove.

Guia do colaborador