Skip to content

Commit

Permalink
More tweaks to zoom out mode hook to simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
jeryj committed Apr 2, 2024
1 parent 431eb85 commit 1188837
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/block-editor/src/hooks/use-zoom-out.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,10 @@ import { store as blockEditorStore } from '../store';
*/
export function useZoomOut( zoomOut = true ) {
const { __unstableSetEditorMode } = useDispatch( blockEditorStore );
const { mode } = useSelect( ( select ) => {
return {
mode: select( blockEditorStore ).__unstableGetEditorMode(),
};
}, [] );
const { __unstableGetEditorMode } = useSelect( blockEditorStore );

const originalEditingMode = useRef( null );
const mode = __unstableGetEditorMode();

useEffect( () => {
// Only set this on mount so we know what to return to when we unmount.
Expand All @@ -31,8 +28,10 @@ export function useZoomOut( zoomOut = true ) {
}

return () => {
// Reset to original mode on unmount
__unstableSetEditorMode( originalEditingMode.current );
// We need to use __unstableGetEditorMode() here and not `mode`, as mode may not update on unmount
if ( __unstableGetEditorMode() !== originalEditingMode.current ) {
__unstableSetEditorMode( originalEditingMode.current );
}
};
}, [] );

Expand Down

0 comments on commit 1188837

Please sign in to comment.