Download wp-calypso/apps/help-center/hooks/use-canvas-mode.js from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 658 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/help-center/hooks/use-canvas-mode.js
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/apps/help-center/hooks/use-canvas-mode.js
-
curl -L -o use-canvas-mode.js https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/apps/help-center/hooks/use-canvas-mode.js
658 Bytes
| import { subscribe, useSelect } from '@wordpress/data'; | |
| import { useEffect, useState } from 'react'; | |
| const useCanvasMode = () => { | |
| const [ canvasMode, setCanvasMode ] = useState( 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 { useCanvasMode }; | |