Hello, I’m having troubles to work with ReactiveVar and createContainer, it is always overwriting the value for some reason and I cannot find out why.
Within the componen there’s a button to load more records from the DB, but whenever I push it and log the result it’s always writing 2, for some reason reactive var value gets reseted every time I push the button.
I’ve also tested with a normal variable to check whether the value was reseted but it worked just as expected, and each button press added 1 to that given variable.
PreAnalisisContainer.jsx
import React from 'react';
import { Meteor } from 'meteor/meteor';
import { createContainer } from 'meteor/react-meteor-data';
import { ReactiveVar } from 'meteor/reactive-var';
import PreAnalisis from '../components/PreAnalisis.jsx'
export default createContainer( ({ params }) => {
let cuadreHandle = null;
let loading = false;
let ficheros = [];
let formatoFicheros = [];
let ficherosExist = false;
const REGISTROS_POR_PAGINA = 3;
const paginaNumero = new ReactiveVar(1);
const cargarMas = () =>{
paginaNumero.set(paginaNumero.get() + 1);
console.log('ReactiveVar vale: ' + paginaNumero.get());
}
cuadreHandle = Meteor.subscribe('cuadre.ficherosSubidos', REGISTROS_POR_PAGINA * paginaNumero.get());
loading = !cuadreHandle.ready();
ficheros = Cuadre.find().fetch();
ficherosExist = !loading && ( ficheros.length > 0 );
return {
loading,
ficheros,
formatoFicheros,
cuadreHandle,
ficherosExist,
cargarMas,
}
}, PreAnalisis);
(component) PreAnalisis.jsx
export default class PreAnalisis extends React.Component {
constructor(props) {
super(props);
}
render() {
return (
<div>
<ul className="list-group">
{this._datosPorSociedad("0049")}
</ul>
<button className="btn btn-primary" onClick={this.props.cargarMas}>Cargar mas...</button>
</div>
);
}