简体   繁体   English

流星ReactJs和第三方js库

[英]Meteor ReactJs and 3rd party js library

I study Meteor with React. 我用React学习流星。 I don't how to do the following: I have 3rd party js library (it is not react or meteor ). 我不怎么做以下事情:我有3rd party js库(它不是react或meteor)。 Library drawing charts and receive data doing http request ( expecting http response as json type ). 库绘制图表并通过http请求接收数据(期望http响应为json类型)。

Question

  • how can I integrate this js library in my meteor + reactjs project to render on the page? 如何在流星+ reactjs项目中集成此js库以在页面上呈现?

  • how should I organize meteor server to response on http request coming from this library 我应该如何组织流星服务器以响应来自此库的http请求

Thanks Oleg 谢谢奥列格

You could put the code of the 3rd party in the client folder, so it will be compiled into your app. 您可以将第三方的代码放在客户端文件夹中,以便将其编译到您的应用中。

Then inside the component using this 3rd party, if the 3rd library requires initialization you should put the init code inside componentDidMount function. 然后,使用第三方在组件内部,如果第三库需要初始化,则应将初始化代码放入componentDidMount函数中。 You should also keep a reference to the 3rd instance, if it requires further interactions: 如果需要进一步的交互,您还应该保留对第三个实例的引用:

class MyComponent extends Component {
  componentDidMount() {
    this.3rdCodeRef = 3rdCode.init();
  }
  render() {
    //...
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM