Load order of Template level?


#1

I problem with load order of template level like this:

<template name...>
   ...........
</template>

// JS
Template.myTpl.onRendered(function(){
   // do something with database
   console.log('on rendered');
})
Template.myTpl.helpers({
   data: function (){
      // do something and get other data from `onRendered` such as Reactive State
      console.log('helper');

      return ....;
   }
})

// Show
helper
on rendered

Sometime helpers load first???
I don’t understand, I think that onRendered load first and helper load second.
Please help me.


#2

TemplateInstance.onRendered is called once everything inside the template that can be rendered, has been rendered. If the helper is not obstructed from being called by some form of template logic, it will be called before the onRendered callback, If it is obstructed then it will be run when the logic allows for that block to be displayed and the helper to run.


#3

Could I always run onRenderd first?
Because I want to set any state to helper.


#4

You’ll want to use onCreated then.


#5

Oh thanks for your helping.


#6

You are very welcome!