用于反应的 wordcloud2 集成

wordcloud2 integration for react

我正在开发一个反应网络应用程序。我想使用 this package 来制作文字云。但它不是反应组件。我如何在我的应用程序中使用它?谢谢大家

实际上很简单,请看一下我设置的沙盒以显示相同的内容 - https://codesandbox.io/s/9435woonpy

解释:

  1. 添加 wordcloud 作为项目的依赖 - npm i --save wordcloud

    In case you're wondering how I got the name of the package, just take a look into the project's package.json - https://github.com/timdream/wordcloud2.js/blob/gh-pages/package.json and look at the name attribute; this is the name with which the project is available in NPM and you confirm this by also looking at the author on the npm page

  2. import 'wordcloud' 到您要使用它的文件中

  3. 有一个空的 canvas ('my-canvas'),您将在其中加载词云

  4. componentDidMount 上,调用 wordcloud api 将词云渲染到 DOM