# 自定义小工具 命名空间:`core/customize-widgets` ## 选择器 ### isInserterOpened 判断插入器是否开启时返回 true _使用示例_ ```js import { store as customizeWidgetsStore } from '@wordpress/customize-widgets'; import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; const ExampleComponent = () => { const { isInserterOpened } = useSelect( ( select ) => select( customizeWidgetsStore ), [] ); return isInserterOpened() ? __( '插入器已开启' ) : __( '插入器已关闭' ); }; ``` _参数_ - _state_ `Object`: 全局应用状态 _返回值_ - `boolean`: 插入器是否开启 ## 操作 ### setIsInserterOpened 返回用于开启/关闭插入器的操作对象 _使用示例_ ```js import { useState } from 'react'; import { store as customizeWidgetsStore } from '@wordpress/customize-widgets'; import { __ } from '@wordpress/i18n'; import { useDispatch } from '@wordpress/data'; import { Button } from '@wordpress/components'; const ExampleComponent = () => { const { setIsInserterOpened } = useDispatch( customizeWidgetsStore ); const [ isOpen, setIsOpen ] = useState( false ); return ( ); }; ``` _参数_ - _value_ `boolean|Object`: 插入器应开启(true)或关闭(false)。要指定插入位置,请使用对象格式 - _value.rootClientId_ `string`: 要插入的根客户端ID - _value.insertionIndex_ `number`: 要插入的索引位置 _返回值_ - `Object`: 操作对象