React Meteor How to execute a function after withTracker data arrives?

I am publishing data from server and catching it using withTracker.

export default withTracker(() => {
    let towndatasub = Meteor.subscribe("userTownDataPublisher",Meteor.userId());
  let resourcedatasub = Meteor.subscribe("userResourcePublisher",Meteor.userId());
    townData : Towns.find({"ownerId":Meteor.userId()}).fetch(),
    resourceData : Resources.find({"ownerId":Meteor.userId()}).fetch()

The problem is i would like to run a function when townData and resourceData arrives.If i call updateResources in componentDidMount i get undefined on this.props.townData and this.props.resourceData

updateResources = () =>{
          //console.log(this.props.resourceData); undefined
          // here i will do something with this.props.resourceData

So where should i call updateResources function to not get undefined ?

Sounds like you can call that function after checking the reactive loading switch. You can get the loading switch like in this snippet:

export default ListPageContainer = withTracker(({ id }) => {
  const todosHandle = Meteor.subscribe('todos.inList', id);
  const loading = !todosHandle.ready();
  const list = Lists.findOne(id);
  const listExists = !loading && !!list;
  return {
    todos: listExists ? list.todos().fetch() : [],

I copied it from the guide

1 Like

check componentDidUpdate lifecycle function of React