Meteor 1.3 & ReactMeteorData - Cant pull data from collection

I’ve been trying to do an import to pull data into a React component but it keeps telling me that Coupons are undefined. I looked in the mongo command line and I can see the record I inserted through astronomy with the MDG validated methods package. Any thoughts to why I would be getting coupons undefined from within getMeteorData()?

I tried it as Coupons and coupons but both return the same undefined.

Exact error: Uncaught ReferenceError: coupons is not defined

Component:

import React, {Component, Proptypes} from 'react';
import {ReactMeteorData} from 'meteor/react-meteor-data';
import reactMixin from 'react-mixin';

export default couponList = ({coupons}) => {
  console.log(coupons);
  return <div>{coupons._id}</div>
};

export default class adminHome extends Component {
  getMeteorData() {
    const handle = Meteor.subscribe('coupons');
    console.log(this);
    return {
      Coupons: coupons.find() || {}
    }
  }
  constructor(props) {
    super(props);
  }
  renderCoupons() {
    console.log(this.data.Coupons);
    return this.data.Coupons.map((coupon) => {
      return <div>ID: coupon._id</div>
    });
  }
  render() {
    return (
      <div>
        <div className="tempContainer">
          <p className="header">Coupons</p>
           <couponList coupons={this.data.Coupons} />
        </div>
      </div>
    );
  }
}
reactMixin(adminHome.prototype, ReactMeteorData);

Collection (In Lib Folder)

import {Meteor} from 'meteor/meteor';
import {Accounts} from 'meteor/accounts-base';
import {Mongo} from 'meteor/mongo';
import {Astro} from 'meteor/jagi:astronomy';
import {Validators} from 'meteor/jagi:astronomy-validators';
import {relations} from 'meteor/jagi:astronomy-relations';
import {timestamp} from 'meteor/jagi:astronomy-timestamp-behavior';
export const Coupons = new Mongo.Collection('coupons');

… Astro class stuff below …

I think you need to import the Coupons collection from the lib file?

Also, I believe exporting couponList as default will be overridden by adminHome. Might want to remove one of them (couponList) to avoid confusion; if you need to export couponList at all?

I had tried it before. I went to retry it again to copy and paste the error i got last time. Weirdly enough it worked, I think it was when I messing around with the publishes/subscriptions. Thank you!

1 Like

Awesome, np. Glad it worked out