Skip to content

Commit

Permalink
Components: refactor ResizableBox to pass exhaustive-deps (#44370)
Browse files Browse the repository at this point in the history
  • Loading branch information
chad1008 authored Sep 28, 2022
1 parent cbaa184 commit cc18f73
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- `Mobile` updated to ignore `react/exhaustive-deps` eslint rule ([#44207](https://github.com/WordPress/gutenberg/pull/44207)).
- `Popover`: refactor unit tests to TypeScript and modern RTL assertions ([#44373](https://github.com/WordPress/gutenberg/pull/44373)).
- `ResizableBox` updated to pass the `react/exhaustive-deps` eslint rule ([#44370](https://github.com/WordPress/gutenberg/pull/44370)).
- `Sandbox`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44378](https://github.com/WordPress/gutenberg/pull/44378))
- `FontSizePicker`: Convert to TypeScript ([#44449](https://github.com/WordPress/gutenberg/pull/44449)).

Expand All @@ -37,6 +38,7 @@
- `UnitControl` updated to pass the `react/exhaustive-deps` eslint rule ([#44161](https://github.com/WordPress/gutenberg/pull/44161)).
- `Notice`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44157](https://github.com/WordPress/gutenberg/pull/44157))


## 21.0.0 (2022-09-13)

### Deprecations
Expand Down
26 changes: 13 additions & 13 deletions packages/components/src/resizable-box/resize-tooltip/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* WordPress dependencies
*/
import { useEffect, useRef, useState } from '@wordpress/element';
import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
import { useResizeObserver } from '@wordpress/compose';

const noop = () => {};
Expand Down Expand Up @@ -84,23 +84,23 @@ export function useResizeLabel( {
*/
const moveTimeoutRef = useRef< number >();

const unsetMoveXY = () => {
/*
* If axis is controlled, we will avoid resetting the moveX and moveY values.
* This will allow for the preferred axis values to persist in the label.
*/
if ( isAxisControlled ) return;
setMoveX( false );
setMoveY( false );
};
const debounceUnsetMoveXY = useCallback( () => {
const unsetMoveXY = () => {
/*
* If axis is controlled, we will avoid resetting the moveX and moveY values.
* This will allow for the preferred axis values to persist in the label.
*/
if ( isAxisControlled ) return;
setMoveX( false );
setMoveY( false );
};

const debounceUnsetMoveXY = () => {
if ( moveTimeoutRef.current ) {
window.clearTimeout( moveTimeoutRef.current );
}

moveTimeoutRef.current = window.setTimeout( unsetMoveXY, fadeTimeout );
};
}, [ fadeTimeout, isAxisControlled ] );

useEffect( () => {
/*
Expand Down Expand Up @@ -143,7 +143,7 @@ export function useResizeLabel( {

onResize( { width, height } );
debounceUnsetMoveXY();
}, [ width, height ] );
}, [ width, height, onResize, debounceUnsetMoveXY ] );

const label = getSizeLabel( {
axis,
Expand Down

0 comments on commit cc18f73

Please sign in to comment.