Skip to content

Instantly share code, notes, and snippets.

@VelichkoAlexander
Last active March 19, 2025 02:21
Show Gist options
  • Save VelichkoAlexander/24f561e1506586d2204e4448f181d346 to your computer and use it in GitHub Desktop.
Save VelichkoAlexander/24f561e1506586d2204e4448f181d346 to your computer and use it in GitHub Desktop.
How to work with preview state for Gutenberg
import {useSelect, useDispatch} from '@wordpress/data'
//Access the current mode value
const { deviceType } = useSelect( select => {
const { __experimentalGetPreviewDeviceType } = select( 'core/edit-post' );
return {
deviceType: __experimentalGetPreviewDeviceType(),
}
}, [] );
//Resize the site editor programmatical
wp.data.dispatch('core/edit-post').__experimentalSetPreviewDeviceType('Tablet');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment