MCPcopy Create free account
hub / github.com/dailydotdev/apps / useCopyText

Function useCopyText

packages/shared/src/hooks/useCopy.ts:92–125  ·  view source on GitHub ↗
(text?: string)

Source from the content-addressed store, hash-verified

90}
91
92export function useCopyText(text?: string): [boolean, CopyNotifyFunction] {
93 const [copying, setCopying] = useState(false);
94 const { displayToast } = useToastNotification();
95
96 const copy: CopyNotifyFunction = async (props = {}) => {
97 const textToCopy = props.textToCopy || text;
98
99 // Nothing to put on the clipboard; writing it anyway pastes "undefined".
100 if (!textToCopy) {
101 displayToast(noTextErrorMessage, { variant: ToastType.Error });
102
103 return;
104 }
105
106 try {
107 await navigator.clipboard.writeText(textToCopy);
108 } catch {
109 displayToast(blockedMessage, { variant: ToastType.Error });
110
111 return;
112 }
113
114 if (!props.disableToast) {
115 displayToast(props.message || defaultMessage, props);
116 }
117
118 setCopying(true);
119 setTimeout(() => {
120 setCopying(false);
121 }, 1000);
122 };
123
124 return [copying, copy];
125}

Callers 9

CodeBoxFunction · 0.90
RenderMarkdownFunction · 0.90
SquadIntelPageFunction · 0.90
MessageActionsFunction · 0.90
SelectionShareBarFunction · 0.90
CredentialRowFunction · 0.90
OAuthClientListItemFunction · 0.90
HowItWorksSectionFunction · 0.90
PluginPageFunction · 0.90

Calls 1

useToastNotificationFunction · 0.90

Tested by

no test coverage detected