diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 5c8643dc08cf6..3525216fcc432 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -54,6 +54,7 @@ - `ResizableBox`: Make drag handles focusable ([#67305](https://github.com/WordPress/gutenberg/pull/67305)). - `CustomSelectControl`: Update correctly when `showSelectedHint` is enabled ([#67733](https://github.com/WordPress/gutenberg/pull/67733)). +- `CustomSelectControl`: Use `useStoreState` to get `currentValue` and avoid stale values ([#67815](https://github.com/WordPress/gutenberg/pull/67815)). ## 28.13.0 (2024-11-27) diff --git a/packages/components/src/custom-select-control/index.tsx b/packages/components/src/custom-select-control/index.tsx index 339944f419872..e014e4bc642ee 100644 --- a/packages/components/src/custom-select-control/index.tsx +++ b/packages/components/src/custom-select-control/index.tsx @@ -149,16 +149,16 @@ function CustomSelectControl< T extends CustomSelectOption >( ); } ); - const { value: currentValue } = store.getState(); + const currentValue = Ariakit.useStoreState( store, 'value' ); const renderSelectedValueHint = () => { const selectedOptionHint = options ?.map( applyOptionDeprecations ) - ?.find( ( { name } ) => store.getState().value === name )?.hint; + ?.find( ( { name } ) => currentValue === name )?.hint; return ( - { store.getState().value } + { currentValue } { selectedOptionHint && (