hello, im new to Meteor 1.3 , i am trying to put my collection data to dataseries in ReactHighchart from https://github.com/kirjs/react-highcharts , but when i call Collection.find().fetch() function it’s return nothing. When i call Collection.find().fetch() with react-komposer it return the Data. Is it new way to call my data collection in Meteor 1.3?
here is my code,
import React from 'react';
var ReactHighcharts = require('react-highcharts');
var Highlight = require('react-highlight');
var ReactDOM = require('react-dom');
var Highcharts = require('highcharts');
export default class Test extends React.Component {
componentDidMount() {
const handle = Meteor.subscribe("data");
console.log(handle);
if (handle.ready()) {
const dataseries = Data.find().fetch();
console.log(dataseries);
let chart = this.refs.chart.getChart();
}
}
render() {
return (
<ReactHighcharts config={config} ref="chart"></ReactHighcharts>
);
}
}
yes, when i’m log the handle it shows the subscription ID, when i write the Data.find().fetch() in javascript console in Chrome i was able to see the return Data, but not when i write the Data.find().fetch() in my JS file. I assume the subscribe and publish is work because when i use it with react-komposer it returns the Data.
Okay - you should look into changing your test component around a bit then, since componentDidMount is invoked only once and is not reactive. So you’ll never get past your handle.ready() check. If you just want to test things out you could wrap your componentDidMount contents in a Tracker.autorun:
That’s definitely the recommended way, but for a quick test there’s nothing wrong with leveraging Tracker.autorun inside (some of) React’s lifecycle methods. Actually, that’s what the react-meteor-data package ultimately does.