2
2
* Modified version of the useClipboard hook from Coder core.
3
3
*@see {@link https://github.com/coder/coder/blob/main/site/src/hooks/useClipboard.ts }
4
4
*/
5
+
6
+ import { displayError } from "components/GlobalSnackbar/utils" ;
5
7
import { useCallback , useEffect , useRef , useState } from "react" ;
6
8
import { useEffectEvent } from "./hookPolyfills" ;
7
9
@@ -40,7 +42,7 @@ export type UseClipboardResult = Readonly<{
40
42
} > ;
41
43
42
44
export const useClipboard = ( input ?:UseClipboardInput ) :UseClipboardResult => {
43
- const { onError : errorCallback , clearErrorOnSuccess= true } = input ?? { } ;
45
+ const { onError= displayError , clearErrorOnSuccess= true } = input ?? { } ;
44
46
45
47
const [ showCopiedSuccess , setShowCopiedSuccess ] = useState ( false ) ;
46
48
const [ error , setError ] = useState < Error > ( ) ;
@@ -53,9 +55,7 @@ export const useClipboard = (input?: UseClipboardInput): UseClipboardResult => {
53
55
return clearTimeoutOnUnmount ;
54
56
} , [ ] ) ;
55
57
56
- const stableOnError = useEffectEvent ( ( ) => {
57
- errorCallback ?.( COPY_FAILED_MESSAGE ) ;
58
- } ) ;
58
+ const stableOnError = useEffectEvent ( ( ) => onError ( COPY_FAILED_MESSAGE ) ) ;
59
59
const handleSuccessfulCopy = useEffectEvent ( ( ) => {
60
60
setShowCopiedSuccess ( true ) ;
61
61
if ( clearErrorOnSuccess ) {