diff --git a/docs/reference-guides/data/data-core-customize-widgets.md b/docs/reference-guides/data/data-core-customize-widgets.md index 3050948edca9c..f4a2e786f413c 100644 --- a/docs/reference-guides/data/data-core-customize-widgets.md +++ b/docs/reference-guides/data/data-core-customize-widgets.md @@ -10,6 +10,24 @@ Namespace: `core/customize-widgets`. Returns true if the inserter is opened. +_Usage_ + +```js +import { __ } from '@wordpress/i18n'; +import { useSelect } from '@wordpress/data'; + +const ExampleComponent = () => { + const { isInserterOpened } = useSelect( + ( select ) => select( 'core/customize-widgets' ), + [] + ); + + return isInserterOpened() + ? __( 'Inserter is open' ) + : __( 'Inserter is closed.' ); +}; +``` + _Parameters_ - _state_ `Object`: Global application state. diff --git a/packages/customize-widgets/src/store/selectors.js b/packages/customize-widgets/src/store/selectors.js index 63962af151d15..d69432cfd1fbd 100644 --- a/packages/customize-widgets/src/store/selectors.js +++ b/packages/customize-widgets/src/store/selectors.js @@ -3,6 +3,23 @@ * * @param {Object} state Global application state. * + * @example + * ```js + * import { __ } from '@wordpress/i18n'; + * import { useSelect } from '@wordpress/data'; + * + * const ExampleComponent = () => { + * const { isInserterOpened } = useSelect( + * ( select ) => select( 'core/customize-widgets' ), + * [] + * ); + * + * return isInserterOpened() + * ? __( 'Inserter is open' ) + * : __( 'Inserter is closed.' ); + * }; + * ``` + * * @return {boolean} Whether the inserter is opened. */ export function isInserterOpened( state ) {