anything-llm/frontend/src/hooks/useCopyText.js
Sean Hatfield 56dc49966d
add copy feature to assistant chat message (#611)
* add copy feature to assistant chat message

* fix tooltip not hiding on mobile

* fix: add tooltips
chore: breakout actions to extendable component + memoize
add CopyText to hook we can reuse
fix: Copy on code snippets broken, moved to event listener
fix: highlightjs patch for new API support
feat: add copy response support

---------

Co-authored-by: timothycarambat <rambat1010@gmail.com>
2024-01-17 16:22:06 -08:00

16 lines
371 B
JavaScript

import { useState } from "react";
export default function useCopyText(delay = 2500) {
const [copied, setCopied] = useState(false);
const copyText = async (content) => {
if (!content) return;
navigator?.clipboard?.writeText(content);
setCopied(content);
setTimeout(() => {
setCopied(false);
}, delay);
};
return { copyText, copied };
}