Skip to content

Commit

Permalink
🗑️ deprecate useElementSize (#473)
Browse files Browse the repository at this point in the history
  • Loading branch information
juliencrn committed Feb 6, 2024
1 parent dddbf01 commit a444ba7
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/stale-items-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"usehooks-ts": minor
---

Depreciated useElementSize replaced by useResizeObserver
5 changes: 1 addition & 4 deletions packages/usehooks-ts/src/useElementSize/useElementSize.md
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
This hook helps you to dynamically recover the width and the height of an HTML element.
Dimensions are updated on load, on mount/un-mount, when resizing the window and when the ref changes.

**Note**: If you use this hook in an SSR context, set the `initializeWithValue` option to `{ width: undefined, height: undefined }` (You can pass it default values when initializing the hook, see example below).
This hook has been **deprecated**, use [`useResizeObserver()`](/react-hook/use-resize-observer) instead.
1 change: 1 addition & 0 deletions packages/usehooks-ts/src/useElementSize/useElementSize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type UseElementSizeResult = [(node: Element | null) => void, Size] &
(Size & { ref: (node: Element | null) => void })

/**
* @deprecated - Use `useResizeObserver` instead.
* A hook for tracking the size of a DOM element.
* @template T - The type of the DOM element. Defaults to `HTMLDivElement`.
* @param {?UseElementSizeOptions} [options] - The options for customizing the behavior of the hook (optional).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ export function WithDebounce() {
})

return (
<div ref={ref} style={{ border: '1px solid palevioletred', width: '100%' }}>
<div
ref={ref}
style={{
border: '1px solid palevioletred',
width: '100%',
resize: 'both',
overflow: 'auto',
maxWidth: '100%',
}}
>
debounced: {width} x {height}
</div>
)
Expand Down
1 change: 1 addition & 0 deletions scripts/updateTestingIssue.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const hookDir = path.resolve('./packages/usehooks-ts/src')
const excludeHooks = [
'useSsr', // @deprecated
'useImageOnLoad', // @deprecated
'useElementSize', // @deprecated
'useIsomorphicLayoutEffect', // Combination of useLayoutEffect and useEffect without custom logic
]

Expand Down

0 comments on commit a444ba7

Please sign in to comment.