Download wp-calypso/apps/wpcom-block-editor/src/wpcom/hooks/use-canvas-mode.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 679 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/wpcom/hooks/use-canvas-mode.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/wpcom-block-editor/src/wpcom/hooks/use-canvas-mode.ts
-
curl -L -o use-canvas-mode.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/wpcom-block-editor/src/wpcom/hooks/use-canvas-mode.ts
679 Bytes
| import { subscribe, useSelect } from '@wordpress/data'; | |
| import { useEffect, useState } from 'react'; | |
| const useCanvasMode = () => { | |
| const [ canvasMode, setCanvasMode ] = useState< string | null >( null ); | |
| const isSiteEditor = useSelect( ( select ) => !! select( 'core/edit-site' ), [] ); | |
| useEffect( () => { | |
| // The canvas mode is limited to the site editor. | |
| if ( ! isSiteEditor ) { | |
| return; | |
| } | |
| const unsubscribe = subscribe( () => { | |
| const mode = new URLSearchParams( window.location?.search ).get( 'canvas' ) || 'view'; | |
| setCanvasMode( mode ); | |
| } ); | |
| return () => unsubscribe(); | |
| }, [ isSiteEditor ] ); | |
| return canvasMode; | |
| }; | |
| export default useCanvasMode; | |