Skip to content

useMeasure does not update when rendering an element conditionally #755

@andbjer

Description

@andbjer

Prior Issues

No prior issues

What is the current behavior?

useMeasure does not update when rendering an element conditionally.

Steps to Reproduce

When using the ref returned by useMeasure on an element that is rendered conditionally the measurements are not updated when the ref.current updates.

I believe the issue is in the useResizeObserver where ref.current is not added to the dependency list, hence the useEffect is not triggered when the ref updates.

Here's a simple reproduction

What is the expected behavior?

The values returned from useMeasure should be updated if the current prop of the ref changes.

Environment Details

  • @react-hookz/web version: 13.2.1
  • react version: 17.0.2
  • react-dom version: 17.0.2
  • typescript version: 4.6.3
  • OS: macOS Monterey (12.3.1)
  • Browser: Google Chrome Version 101.0.4951.64
  • Did this work in previous versions? No

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions