Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using react-meteor-data from Typescript

Question:

How do I use react-meteor-data with Typescript?

Background:

I'm just getting going on a new project and would like to use Meteor.

According to what I've been reading (link) the recommendation seems to be to use React with Meteor for new projects. Great I wanted to learn React anyway.

And since I'm a Java programmer, I'd really like to use 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?

I believe I'm supposed to use react-meteor-data but if I run typings search meteor add react-meteor-data I find nothing.

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. That would make my life a lot easier. Any takers?

like image 301
MrQBerrt Avatar asked Jul 03 '26 01:07

MrQBerrt


2 Answers

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:

declare module 'meteor/react-meteor-data' {
  function createContainer(
    getMeteorData: (props?: Object) => Object,
    component: React.ComponentClass<any> | React.StatelessComponent<any>,
  ): React.ComponentClass<any>;
}
like image 73
Waiski Avatar answered Jul 05 '26 13:07

Waiski


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

Other typings are available at https://github.com/meteor-typings/ including the flow-router.

In my tsconfig.json, I added:

"types": ["meteor-typings"]

but you might not need to do that.

like image 37
SRMelody Avatar answered Jul 05 '26 13:07

SRMelody



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!