Shivam Rawat
Shivam Rawat

Reputation: 41

What exactly Template.currentData() in meteor is useful for?

I am not able to understand exactly what Template.currentData() do. What I can understand from the documentation is I can use this to pass data from one template to another template but I can't find any example showing how to do that.

Also, I think we can achieve all the functionality provided by Template.currentData() from Session variable. Please let me know if I am wrong about this statement and why?

Upvotes: 0

Views: 735

Answers (1)

Ankur Soni
Ankur Soni

Reputation: 6018

As the documentation suggests, The purpose of using Template.currentData() differs in the various utility like either helpers, events or callbacks of templates.

  1. Inside an onCreated, onRendered, or onDestroyed callback, returns the data context of the template.
  2. Inside an event handler, returns the data context of the template on which this event handler was defined.
  3. Inside a helper, returns the data context of the DOM node where the helper was used.

NOTE: Template.currentData() Establishes a reactive dependency on the result.

You can refer the already existing discussion on SO here

You can click here for more information

Upvotes: 1

Related Questions