如何在react-wordcloud中下载wordcloud为图片?

How to download wordcloud as picture in react-wordcloud?

如何在react-wordcloud中下载wordcloud为图片?或者有没有react包可以plot wordcloud和下载图片?

这是一个简单的方法..

import React, {createRef} from 'react';
import ReactWordcloud from 'react-wordcloud';
import { saveSvgAsPng } from 'save-svg-as-png';
import {Button} from 'antd';

const saveWordCloudToImage= () => {
   const wordcloudRef = createRef();
//   const words = //your words object;


   const handleSave = () => {
        const svgElement = wordcloudRef.current.querySelector('svg');
        saveSvgAsPng(svgElement, 'wordcloud.png');
   };

   return (
      <>
          <span ref={wordcloudRef}>
             <ReactWordcloud  words={words}/>
          </span>
          <Button onClick={handleSave}>Save</Button>
      </>
   )
};