The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/client/hooks/useClipboard.js

26 lines
725 B

import { useCallback } from 'react';
import PropTypes from 'prop-types';
import { useTranslation } from '../contexts/TranslationContext';
import { useToastMessageDispatch } from '../contexts/ToastMessagesContext';
export default function useClipboard(text) {
const t = useTranslation();
const dispatchToastMessage = useToastMessageDispatch();
const onClick = useCallback((e) => {
e.preventDefault();
try {
navigator.clipboard.writeText(text);
dispatchToastMessage({ type: 'success', message: t('Copied') });
} catch (e) {
dispatchToastMessage({ type: 'error', message: e });
}
}, [dispatchToastMessage, t, text]);
return onClick;
}
useClipboard.propTypes = {
text: PropTypes.string.isRequired,
};