Question about the MongoDB collection section of the meteor react tutorial

Hi, I am having some trouble implementing the tutorial to my own project. My problem is that I can’t figure out how to use the “Tasks.find({}).fetch()” in a situation where I don’t have the “Task:” before it like in the tutorial. For example how could I just console.log the output of it, I tried doing this by creating a render() function in the export default withTracker class, but this did not work. I feel like the answer to this is very obvious but i can’t figure it out since I’m very new to Meteor, React JS and MongoDB.

Link to the tutorial: https://www.meteor.com/tutorials/react/collections
Section: 3.4

The code I tried implementing:

import React, {Component} from ‘react’;
import {withTracker} from ‘meteor/react-meteor-data’;
import {SavedFractals} from ‘…/api/savedfractals.js’;

class Share extends Component {

}

export default withTracker(() => {
render() {
console.log(SavedFractals.find({}).fetch());
}
})(Share);

If you’re just trying to log it, then log it.

import React, { Component } from 'react';
import { withTracker } from 'meteor/react-meteor/data';
import { SavedFractals } from '../api/savedfractals.js';

class Share extends Component {
  render() {
    return null;
  }
}

export default withTracker(() => {
  const fractals = SavedFractals.find({}).fetch();
  console.log(fractals):
  return {}
})(Share);

withTracker is a wrapped around a component. It wraps your component with a component that tracks data, and re-renders your component when that data changes.

Anything you return from the withTracker callback will be passed into your component as a prop. So returning { fractals: fractals } would pass fractals as a prop into your component.

render is a lifecyle method for a react component. Putting it inside of the tracker won’t do anything. https://reactjs.org/docs/react-component.html

Thanks for the help! It’s working perfectly now. :grinning: