How to access variable inside


I’d like to access variable inside

Here, I have numStudys inside, and console.log() inside correctly shows the value of numStudys (in my case, 4, which is correct), but console.log() outside just keep showing “undefined”.

Is there any ways that I can access numStudys inside, and get the value (in my case, 4)?

export default class StudyPage extends React.Component {
componentDidMount() {
Tracker.autorun(() => {‘studys.count’, (error, result) => {
numStudys = result;
console.log("numStudys inside ", numStudys);
console.log("numStudys outside ", this.numStudys);

My result
numStudys outside undefined
numStudys inside 4


Why do you need to? I think both Meteor call and Tracker autorun are async functions, so you will never get the value outside of the functions with regular vanilla JS. You can store it in the component’s state once you have the value available in the callback (if the value is important to the component’s UI or something similar).


Hi - you can use futures in MeteorMethods function to ensure the client “waits” until the “result” is returned to it from the That is, the client will just wait for the result to be returned before continuing, using futures. An example could be something like this:

/* In MeteorMethods.jsx on the Server */

import Future from ‘fibers/future’ ;
import { Meteor } from ‘meteor/meteor’ ;


studysCount: function() {

let future = new Future() ;

let STUDYSCOUNT = null ;
STUDIESCOUNT = Studies.count() ;
future.return( STUDIESCOUNT ) ;

return future.wait() ;


Google meteor futures and meteor to get more info.