Load order of Template level?

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.

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.

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

You’ll want to use onCreated then.

Oh thanks for your helping.

1 Like

You are very welcome!