如何将外部 JS api 添加到 ReactJS 项目?

How do I add an external JS api to a ReactJS project?

我在 ReactJS 项目中与我一起工作的团队成员给了我一个外部 API。该文件看起来像这样 https://dev.wavemakerfutureproof.co.uk/futureproof-sdk.js

我想知道最好的方法是利用这个 API 提供的所有方法,因为我认为这不像 ReactJS 项目中包含的大多数东西那样工作。 IE。从“...”导入“...”

非常感谢任何帮助!

你可以从模板 html 导入 JSFile,像这样

<html>
<script src ="https://dev.wavemakerfutureproof.co.uk/futureproof-sdk.js" ></script>
</html>

这取决于您是否使用 create-react-app 来开发您的 React 应用程序,将您的脚本放入您的 index.html 或应用程序的条目 html:

<script src ="https://dev.wavemakerfutureproof.co.uk/futureproof-sdk.js" ></script>

这有一个 github 问题,请阅读下面 URL 了解更多详情:

https://github.com/facebook/create-react-app/issues/3007