MCPcopy Create free account
hub / github.com/adobe/react-spectrum / useCopyAIImport

Function useCopyAIImport

packages/dev/s2-docs/src/AIIconSearchView.tsx:98–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

96];
97
98export function useCopyAIImport() {
99 let [copiedId, setCopiedId] = useState<string | null>(null);
100 let timeout = useRef<ReturnType<typeof setTimeout> | null>(null);
101
102 let handleCopyImport = useCallback((id: string) => {
103 if (timeout.current) {
104 clearTimeout(timeout.current);
105 }
106 navigator.clipboard
107 .writeText(`import {${id}} from '@react-spectrum/ai/loader';`)
108 .then(() => {
109 setCopiedId(id);
110 timeout.current = setTimeout(() => setCopiedId(null), 2000);
111 })
112 .catch(() => {
113 ToastQueue.negative('Failed to copy import statement.');
114 });
115 }, []);
116
117 return {copiedId, handleCopyImport};
118}
119
120const itemStyle = style({
121 ...focusRing(),

Callers 1

AIIconsPageSearchFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected