简体   繁体   English

使用来自Typescript的react-meteor-data

[英]Using react-meteor-data from Typescript

Question: 题:

How do I use react-meteor-data with Typescript? 如何在Typescript中使用react-meteor-data?

Background: 背景:

I'm just getting going on a new project and would like to use Meteor. 我刚开始一个新项目,并想使用Meteor。

According to what I've been reading ( link ) the recommendation seems to be to use React with Meteor for new projects. 根据我一直在阅读的内容( 链接 ),建议似乎是将React与Meteor一起用于新项目。 Great I wanted to learn React anyway. 太棒了,我还是想学习React。

And since I'm a Java programmer, I'd really like to use Typescript. 而且由于我是Java程序员,所以我真的很想使用Typescript。

But I'm having a lot of trouble with this trio of technologies. 但是,这三项技术给我带来了很多麻烦。

Specifically, how do I hook up react components to meteor containers? 具体来说,如何将React组件连接到流星容器?

I believe I'm supposed to use react-meteor-data but if I run typings search meteor add react-meteor-data I find nothing. 我相信我应该使用react-meteor-data,但是如果我运行typings search meteor add react-meteor-data我什么也找不到。

Where do I go from here? 我从这里去哪里?

Extra-Credit: 额外信用:

What I would really like is for the Todo App with React tutorial to be rewritten by someone for use with Typescript. 我真正想要的是由某人重写的带有ReactTodo App教程,以用于Typescript。 That would make my life a lot easier. 那将使我的生活更加轻松。 Any takers? 有没有人?

Based on what I've been reading, this is an awkward time for the Javascript community in general and for the Meteor community specifically. 根据我一直在阅读的内容,对于一般的Javascript社区,特别是对于Meteor社区,这是一个尴尬的时期。 With the introduction of things like Webpack, Typescript, Flow, Angular2, React and a host of other new tools and technologies, it is painful to start a Meteor project right now (so long as you want to use some of those modern technologies). 随着诸如Webpack,Typescript,Flow,Angular2,React以及许多其他新工具和技术的引入,现在启动Meteor项目很痛苦(只要您想使用其中的一些现代技术)。 Perhaps it will be easy again soon. 也许不久之后又会很容易。

Here were some very helpful articles: 这里有一些非常有用的文章:

  1. State of Meteor (part 1) 流星状态(第1部分)
  2. State of Meteor (part 2) 流星状态(第2部分)

As a result of all of this, I decided to go with Express for now. 由于所有这些,我决定暂时使用Express。

There seems to be no type package for react-meteor-data at the moment, but you can just put this declaration in some .d.ts file of yours, I think it's good enough: 目前似乎没有用于react-meteor-data类型包,但是您可以将该声明放入您自己的.d.ts文件中,我认为这已经足够了:

declare module 'meteor/react-meteor-data' {
  function createContainer(
    getMeteorData: (props?: Object) => Object,
    component: React.ComponentClass<any> | React.StatelessComponent<any>,
  ): React.ComponentClass<any>;
}

The excellent meteor-typings project has a bunch of meteor types available. 优秀的流星分型项目有很多可用的流星类型。 react-meteor-data has typings available here: https://github.com/meteor-typings/react-meteor-data react-meteor-data在这里有可用的类型: https : //github.com/meteor-typings/react-meteor-data

Other typings are available at https://github.com/meteor-typings/ including the flow-router. 其他类型可以在https://github.com/meteor-typings/获得,包括流路由器。

In my tsconfig.json, I added: 在我的tsconfig.json中,我添加了:

"types": ["meteor-typings"]

but you might not need to do that. 但您可能不需要这样做。

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

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