import { useSyncExternalStore } from 'react' import { clipboardEvent } from './index' import type { EventState } from '../../index' import type { ClipboardState } from './types' let self: EventState const subscribe = (callback = () => {}) => { self({ callback }).mount() return () => self({ callback }).clean() } const getSnapshot = () => self.snapshot export const useClipboard = () => { if (!self) self = clipboardEvent() const [ret] = useSyncExternalStore(subscribe, getSnapshot, getSnapshot) return ret }