streamich/react-use

[useMeasure] Ability to track a custom Ref

开放

#1,227 创建于 2020年5月18日

 (15 条评论) (19 个反应) (0 位负责人)TypeScript (3,273 个派生)batch import
good first issuehelp wanted

仓库指标

星标
 (43,979 个星标)
PR 合并指标
 (PR 指标待抓取)

描述

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.

贡献者指南