Skip to content

Commit

Permalink
Refactor to get isZoomedOut within useSelect
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Dec 4, 2024
1 parent 8c4eb48 commit 9437d4e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,19 @@ export function useZoomOut( enabled = true ) {
const { setZoomLevel, resetZoomLevel } = unlock(
useDispatch( blockEditorStore )
);
const { isZoomOut } = unlock( useSelect( blockEditorStore ) );

const isZoomedOut = isZoomOut();
/**
* We need access to both the value and the function. The value is to trigger a useEffect hook
* and the function is to check zoom out within another hook without triggering a re-render.
*/
const { isZoomedOut, isZoomOut } = useSelect( ( select ) => {
const { isZoomOut: _isZoomOut } = unlock( select( blockEditorStore ) );
return {
isZoomedOut: _isZoomOut(),
isZoomOut: _isZoomOut,
};
}, [] );

const controlZoomLevelRef = useRef( false );
const isEnabledRef = useRef( enabled );

Expand Down

0 comments on commit 9437d4e

Please sign in to comment.