Skip to content

Commit

Permalink
Components: refactor AlignmentMatrixControl to pass `exhaustive-dep…
Browse files Browse the repository at this point in the history
…s` (#41167)

* destructure `compsite.setCurrentId` outside of effect to avoid a loop. Update dependency array

* Components: update changelog

* Update packages/components/CHANGELOG.md

* Update packages/components/CHANGELOG.md

* Update packages/components/CHANGELOG.md

Co-authored-by: Marco Ciampini <marco.ciampo@gmail.com>
  • Loading branch information
chad1008 and ciampo authored May 23, 2022
1 parent 20f6ca5 commit 868aaf1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Internal

- `AlignmentMatrixControl` updated to satisfy `react/exhuastive-deps` eslint rule ([#41167](https://github.com/WordPress/gutenberg/pull/41167))
- `CheckboxControl`: Add unit tests ([#41165](https://github.com/WordPress/gutenberg/pull/41165)).

## 19.11.0 (2022-05-18)
Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/alignment-matrix-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ export default function AlignmentMatrixControl( {
onChange( nextValue );
};

const { setCurrentId } = composite;

useEffect( () => {
if ( typeof value !== 'undefined' ) {
composite.setCurrentId( getItemId( baseId, value ) );
setCurrentId( getItemId( baseId, value ) );
}
}, [ value, composite.setCurrentId ] );
}, [ value, setCurrentId, baseId ] );

const classes = classnames(
'component-alignment-matrix-control',
Expand Down

0 comments on commit 868aaf1

Please sign in to comment.