import { useCallback } from 'react' import download from 'downloadjs' import { RCTResponderProps } from '~/components/RenderIOCall' import ObjectViewer from '~/components/ObjectViewer' import { toast as notify } from 'react-hot-toast' import useCopyToClipboard from '~/utils/useCopyToClipboard' import CheckIcon from '~/icons/compiled/Check' import CopyIcon from '~/icons/compiled/Copy' import DownloadIcon from '~/icons/compiled/DownloadsFolder' export default function DisplayObject({ label, data, }: RCTResponderProps<'DISPLAY_OBJECT'>) { const { onCopyClick, isCopied } = useCopyToClipboard() const handleCopyJson = useCallback(() => { try { onCopyClick(JSON.stringify(data, null, 2)) } catch (err) { console.error('Failed generating JSON', err) notify.error('Failed generating text to copy.') } }, [data, onCopyClick]) const handleDownloadJson = useCallback(() => { try { download( JSON.stringify(data, null, 2), `${label ?? 'data'}.json`, 'application/json' ) } catch (err) { console.error('Failed generating download', err) notify.error('Failed generating the download.') } }, [data, label]) return (
{label}
) }