[solved] I can't use ReactiveVar in a blaze helper

I am a bit confused about my code not working as I expected.
I am just initializing a reactive-var in my template onCreated method, and trying to read it in a helper. But I got undefined from the reactive-var.

Here is the code :

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import './record-infos-page.html';
import './record-infos-page.scss';

Template.Record_infos_page.onCreated(function recordInfosPageOnCreated() {
  this.checkedVariablesIds = new ReactiveVar(['HkcEjZjdxbobbNCZc', 'uTmJKTfoWFFfXPMwx']);
  console.log(1, this.checkedVariablesIds.get());

  checkedVariablesIds() {
    const checkedVariablesIds = Template.instance().checkedVariablesIds.get();
    console.log(2, checkedVariablesIds);
    return checkedVariablesIds;

And here is the console.log result:

1 ["HkcEjZjdxbobbNCZc", "uTmJKTfoWFFfXPMwx"]
2 undefined

So my reactive var is well initialized, but is not passed to the helper. Why?

1 Like

I don’t know. I’ve just copied and pasted your code and it works fine with my template. Maybe let’s see your Record_infos_page template?

1 (2) ["HkcEjZjdxbobbNCZc", "uTmJKTfoWFFfXPMwx"]
  0: "HkcEjZjdxbobbNCZc"
  1: "uTmJKTfoWFFfXPMwx"
  length: 2
  __proto__: Array(0)
2 (2) ["HkcEjZjdxbobbNCZc", "uTmJKTfoWFFfXPMwx"]
  0: "HkcEjZjdxbobbNCZc"
  1: "uTmJKTfoWFFfXPMwx"
  length: 2
  __proto__: Array(0)

This is the HTML:

<template name="Record_infos_page">
  <section id="record-info-page">
    <section id="graph-right-panel">
    {{> Record_graph_container variablesIds=checkedVariablesIds}}

Nothing special here, so I guess I should investigate in the child template

Ok it is solved. My bad, I had another helper in my child template that erased my reactiveVar. Thanks for your help :wink: