Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compose: Add types to useResizeObserver and type checking to useIsomorphicLayoutEffect #32111

Merged
merged 1 commit into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions packages/compose/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ _Returns_
Hook which allows to listen the resize event of any target element when it changes sizes.
_Note: `useResizeObserver` will report `null` until after first render_

Simply a re-export of `react-resize-aware` so refer to its documentation <https://github.com/FezVrasta/react-resize-aware>
for more details.

_Related_

- <https://github.com/FezVrasta/react-resize-aware>

_Usage_

```js
Expand All @@ -421,10 +428,6 @@ const App = () => {
};
```

_Returns_

- `Array`: An array of {Element} `resizeListener` and {?Object} `sizes` with properties `width` and `height`

<a name="useThrottle" href="#useThrottle">#</a> **useThrottle**

Throttles a function with Lodash's `throttle`. A new throttled function will
Expand Down
5 changes: 4 additions & 1 deletion packages/compose/src/hooks/use-resize-observer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import useResizeAware from 'react-resize-aware';
* Hook which allows to listen the resize event of any target element when it changes sizes.
* _Note: `useResizeObserver` will report `null` until after first render_
*
* @return {Array} An array of {Element} `resizeListener` and {?Object} `sizes` with properties `width` and `height`
* Simply a re-export of `react-resize-aware` so refer to its documentation <https://github.com/FezVrasta/react-resize-aware>
* for more details.
*
* @see https://github.com/FezVrasta/react-resize-aware
*
* @example
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useState, useCallback } from '@wordpress/element';
/**
* Hook which allows to listen the resize event of any target element when it changes sizes.
*
* @return {Array} An array of {Element} `resizeListener` and {?Object} `sizes` with properties `width` and `height`
* @return {[JSX.Element, { width: number, height: number } | null]} An array of {Element} `resizeListener` and {?Object} `sizes` with properties `width` and `height`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the React Native version a completely different implementation of the web version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm asuming react-resize-aware doesn't work for react native 🤷‍♀️ In any case it's outside the scope of this PR. They have the exact same API FWIW.

*
* @example
*
Expand Down
2 changes: 2 additions & 0 deletions packages/compose/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
"src/hooks/use-constrained-tabbing/**/*",
"src/hooks/use-debounce/**/*",
"src/hooks/use-instance-id/**/*",
"src/hooks/use-isomorphic-layout-effect/**/*",
"src/hooks/use-focus-return/**/*",
"src/hooks/use-previous/**/*",
"src/hooks/use-media-query/**/*",
"src/hooks/use-reduced-motion/**/*",
"src/hooks/use-merge-refs/**/*",
"src/hooks/use-resize-observer/**/*",
"src/utils/**/*"
]
}